自学C++编写的代码无法运行,请求帮忙排查错误
C++代码错误分析与修正
存在的错误
- 误用中文全角引号:代码里所有输出字符串使用的是中文双引号
“”,而C++编译器只识别英文半角引号""作为字符串的边界符号,这会直接导致编译失败。
修正后的代码
#include <iostream> #include <string> using namespace std; int main() { // Declare a variable to store an integer int inputNumber; cout << "Enter an integer: "; // store integer given user input cin >> inputNumber; // The same with text i.e. string data cout << "Enter your name: "; string inputName; cin >> inputName; cout << inputName << " entered " << inputNumber << endl; return 0; }
内容的提问来源于stack exchange,提问作者Hitesh Singh
相关产品推荐
相关产品推荐

