我没有C++的经验-我今天开始学习,我不明白为什么会出现编译错误。该信息位于代码下方。
#include "stdafx.h"
#include <iostream>
int main()
{
using namespace std;
cout << "Would you like to use this program?";
string yn;
cin >> yn;
if (yn == "y")
{
cout << "Continuing...";
}
else {
cout << "Exiting...";
}
return 0;
}
“cin >> yn;”部分是什么显然导致编译错误,并且“>>”用红色下划线标出,有人知道我做错了什么吗?如果这可能与我有任何关系,我也会使用Microsoft Visual Studio 2013。
最佳答案
您必须包含标题<string>
#include <string>
在此 header 中,类
operator <<
(operator >>
)声明了std::string
和std::basic_string
。
关于c++ - 我不确定如何解决此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27845628/