【发布时间】:2012-02-12 20:58:46
【问题描述】:
我知道很多人之前都遇到过这个错误,但我刚开始用 C++ 编程,所以我还不确定大多数命令。
我正在尝试使用以下源代码创建程序:
#include <iostream>
int main()
{
char input[7];
std::cout << "Enter your gender (male or female):";
std::cin.getline (input, 6);
if (input == "male")
char reply[] = "Mr";
else
char reply[] = "Mrs";
std::cout << "Hello " << reply << "!\n";
return 0;
}
现在,当我尝试使用我的编译器 (G++) 编译它时。我收到了这个错误:
StringTest.cpp: In function 'int main()':
StringTest.cpp: 16:26: error: 'reply' was not declared in this scope
您能告诉我我的代码到底出了什么问题吗?我应该如何尝试解决它?
谢谢你, Xarlexus
【问题讨论】:
标签: c++ string if-statement scope compiler-errors