0

Hey Guys i seem to be having an issue with the follwoing code when i complie in VC++ 2010. It compiles fine in both minGW and VC++ 2008. The code is as follows...

The Program accepts three inputs whereby it outputs them in alphabetical order, very simple.

#include <iostream>
#include <vector>
#include <algorithm>

using std::cout; using std::cin; using std::endl;

using std::string; using std::vector;



int main()
{
 string Student_Name;

    vector<string>STUDENTS_NAME;
        for (int A=0; A<=3; A++)
        {
            cout<<"Enter a students name: ";
             if(cin>>Student_Name)
             STUDENTS_NAME.push_back(Student_Name);
             sort(STUDENTS_NAME.begin(),STUDENTS_NAME.end());
        }
               for (int B=0; B<=3; B++)
               {
                cout << STUDENTS_NAME[B];
                cout << endl;
               }
return 0;
}

I think the problematic lines are as follows as intellisense tells me "Error: no operator ">>"matches these operands"

if(cin>>Student_Name)
cout << STUDENTS_NAME[B];

When the code is compiled the error is as follows:
error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)

Any help much appreciated, :)

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by God Coder123
0

Clearly Visual C++ 2010 is smarter in terms of implicit standard headers. You failed to include <string>, and the compiler rightly complains. The others don't complain because <string> is probably included inside one of the other three standard headers you've included, so the bug goes unnoticed.

Edited by Narue: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.