[英]reading string in c++
In the Dev C++
compiler I can write and successfully compile this: 在
Dev C++
编译器中,我可以编写并成功编译它:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string method;
cin >> method;
return 0;
}
but when I wrote the above code in Visual Studio 2013 (console app mode)
I got this error: 但是当我在
Visual Studio 2013 (console app mode)
编写上述代码时,我收到此错误:
Error: no operator ">>" matches these operands
operand types are: std::istream >> std::string
in Visual Studio
: 在
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 the error tells me. 我明白错误告诉我的是什么。 But why in only
Visual Studio 2013
? 但为什么只在
Visual Studio 2013
?
尝试在其他标题之前放置标题“stdafx.h”。
#include "stdafx.h"
simple exlample for read string in visual studio : 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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.