c++ - 我不确定如何解决此错误

标签 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;
}

“cin >> yn;”部分是什么显然导致编译错误,并且“>>”用红色下划线标出,有人知道我做错了什么吗?如果这可能与我有任何关系,我也会使用Microsoft Visual Studio 2013。

最佳答案

您必须包含标题<string>

#include <string>

在此 header 中,类operator <<(operator >>)声明了std::stringstd::basic_string

关于c++ - 我不确定如何解决此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27845628/

相关文章:

gwt - 使用跨站点支持编译 GWT 代码时出错

c++ - VC++ 2008 中的模板数组

c++ - 在 C++ 中返回对局部变量的引用

C++ 本地容器

c++ - 无法打开包含文件错误但能够找到文件

c - 在C中如何使用printf输出球坐标转换为笛卡尔坐标的值?

c++ - 对于不是伟大程序员的测试人员来说,什么是好的编程语言?

c++ - 什么是聚合初始化

android - 如何使我的编译器显示带有空格的结果?

c++ - C++使用代码生成错误