Reading a string in C ++
In the compiler, Dev C++
I can write and successfully compile this:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string method;
cin >> method;
return 0;
}
but when i wrote the code above in Visual Studio 2013 (console app mode)
i got this error:
Error: no operator ">>" matches these operands
operand types are: std::istream >> std::string
EDIT
in Visual Studio
:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string method;
cin >> method;
return 0;
}
I understand what he says about the error. But why only Visual Studio 2013
?
+3
Mirjalal Talishinski
source
to share
2 answers
Try placing the "stdafx.h" header in front of other headers.
#include "stdafx.h"
+2
Vlad from Moscow
source
to share
simple exlample for read line in visual studio:
#include "stdafx.h"
#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
int main()
{
std::string str ;
getline(cin, str);
cout << str;
_ getch();
return 0;
}
+1
msn
source
to share