编译器拒绝使用C ++控制台程序

时间:2016-01-02 03:55:32

标签: c++

我正在阅读C++ ALL-IN-ONE for Dumies 6-In-1,正在阅读有关字符串的章节,请参阅此代码段:

#include <iostream>
using namespace std;

int main() 
{
    string mystring;
    mystring = "Hello there";
    cout << mystring <<endl;
    return 0;
}

所以我在Visual Studio中创建了自己的示例(项目保存为控制台项目):

// ConsoleApplication1.cpp : Defines the entry point for the console application.
// 
#include "stdafx.h"
#include <iostream> 
#include <ostream>
using namespace std;
int main()
{
    int NumberX, NumberY, NumberZ, NumberTotal;
    NumberX = 12;
    NumberY = 13;
    NumberZ = 14;

    NumberTotal = NumberX + NumberY + NumberZ;
    char Derp;
    Derp = 'D';
    string Derpy;
    Derpy = "Really";
    char DerpX;
    DerpX = Derpy[2];
    cout << Derpy;
    cout << endl;
    system("pause");
    return 0;
}

但是,Visual Studio会在<<中突出显示cout << Derpy;,并且不允许它运行。这是VS选择的代码中唯一的错误。

    IntelliSense: no operator "<<" matches these operands
        operand types are: std::ostream << std::string

如何成功回显变量Derpy?

0 个答案:

没有答案