使用cout时的编译错误

时间:2016-06-30 01:18:34

标签: c++

我有编译错误只是输出cout消息。以下是我的代码:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
    char letter = 'a';
    short age = 10;
    int cout = 575;
    long numStars = 985632145;
    float pi = 3.1;
    double price = 89.65;
    string season = "summer";

    cout << "Letter: "<< letter << endl;
    std::cout << "Age: " << age<< endl;
    std::cout << "Cout: " << cout << endl;
    std::cout << "Number Stars: " << numStars << endl;
    std::cout << "Pi: " << pi << endl;
    std::cout << "Price: " << price << endl;
    std::cout << "Season: " << season;


    system("pause");
    return 0;
}

我得到的错误就行了:

cout << "Letter: "<< letter << endl;

我尝试重新安装VS2015,但这没有帮助。

1 个答案:

答案 0 :(得分:2)

您有一个名为int的{​​{1}}类型的变量 - 鉴于您是cout,这是不允许的。将此变量名称更改为其他名称,并避免使用语句using namespace std

using namespace std是“保留类型/关键字”,因此您无法将其用作变量名称。