无法分配值

时间:2015-03-17 16:44:14

标签: c++

我是c ++语言的新手。 我正在使用code lite来编码。 这是我的代码。

#include <stdio.h>

int main(int argc, char **argv)
{

int age1;
int age2;   
    cout<<"Enter Age of First Kid";
    cin >> age1;
        cout<<"Enter Age of Second Kid";
cin>>age2;
}

但它给了我这个错误

C:/myWorkspace/practise/main.cpp:8:2: error: 'cout' was not declared in this scope

请告诉我我在哪里做错了。 感谢。

2 个答案:

答案 0 :(得分:1)

试试这个:

#include <iostream>

int main(int argc, char **argv)
{

    int age1;
    int age2;   
    std::cout<<"Enter Age of First Kid";
    std::cin >> age1;
    std::cout<<"Enter Age of Second Kid";
    std::cin>>age2;
}

答案 1 :(得分:1)

您只需在using namespace std;之前添加main即可完成此项工作。

注意:在某些情况下,这可能会导致问题。这没关系。

此外,您使用了错误的标题。使用<iostream>代替<stdio.h>


这将有效

#include <iostream>

using namespace std;

int main(int argc, char **argv)
{

int age1;
int age2;   
cout<<"Enter Age of First Kid";
cin >> age1;
cout<<"Enter Age of Second Kid";
cin>>age2;

return 0; // it's better to inform the system everything's OK
}
相关问题