我不确定如何解决这个错误

时间:2015-01-08 17:04:12

标签: c++ compiler-errors

我没有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;
}

&#34; cin&gt;&gt;部分炔;&#34;是什么显然导致编译错误和&#34;&gt;&gt;&#34;红色下划线,有谁知道我做错了什么?我也在使用Microsoft Visual Studio 2013,如果它可能与它有任何关系。

1 个答案:

答案 0 :(得分:3)

您必须包含标题<string>

#include <string>

正是这个标题为operator << operator >>std::string} {/ p>宣布了std::basic_string和{{1}}