这段代码有什么错误?

时间:2011-05-19 13:45:20

标签: c++

void main (void)
{
    char name [2] [30], number [2] [10];
    char << "Please type your first name, a blank, and last name) << endl;
    cin >> name;
    cout << "Name=" <<name << endl;
    cout << "Please type a number, press the return key, and another number << endl;
    cin >> number [0] >> endl;
    cout << number << endl; 
}

4 个答案:

答案 0 :(得分:5)

太多了,但我们不是来做家庭作业。检查编译器的输出,然后一次处理一个:


qq.cpp:4:13: warning: missing terminating " character
qq.cpp:4: error: missing terminating " character
qq.cpp:7:13: warning: missing terminating " character
qq.cpp:7: error: missing terminating " character
qq.cpp:1: error: ‘::main’ must return ‘int’
qq.cpp: In function ‘int main()’:
qq.cpp:4: error: expected unqualified-id before ‘<<’ token
qq.cpp:6: error: ‘cout’ was not declared in this scope
qq.cpp:6: error: ‘endl’ was not declared in this scope
qq.cpp:8: error: ‘cin’ was not declared in this scope

至少:

  • 没有using子句或std::前缀。
  • char不是一个流。
  • 某些字符串文字没有收尾报价。

答案 1 :(得分:1)

"Please type your first name, a blank, and last name)

的末尾有一个括号而不是双引号

答案 2 :(得分:1)

您不会使用“in in

结束字符串
char << "Please type your first name, a blank, and last name) << endl;

cout << "Please type a number, press the return key, and another number << endl;

它应该是:

int main (void)
{
char name [2] [30], number [2] [10];
char << "Please type your first name, a blank, and last name)" << endl;
cin >> name;
cout << "Name=" <<name << endl;
cout << "Please type a number, press the return key, and another number" << endl;
cin >> number [0] >> endl;
cout << number << endl;
return 0;
}

答案 3 :(得分:1)

char << "Please type your first name, a blank, and last name) << endl;

cout << "Please type a number, press the return key, and another number << endl;

都缺少结束双引号

char << "Please type your first name, a blank, and last name)" << endl;
cout << "Please type a number, press the return key, and another number" << endl