我在尝试使用 std::string 时遇到了巨大的困难。该程序编译得很好,但是当我运行该程序时,我收到此错误:error
我在谷歌上到处查看,但没有找到关于如何解决这个问题的信息。我还尝试以不同的方式编写代码,看看这是否能告诉我什么。
std::string yourName;
std::cout << "What is your name?";
std::cin >> yourName;
std::cout << "Hello, " << yourName << std::endl;
Run Code Online (Sandbox Code Playgroud)
尽管重写了,我仍然遇到同样的错误,并且我没有忘记包含 iostream 和字符串头文件。
我正在使用 GCC 编译器,我的编译代码是g++ -std=c++14 test.cpp -o test.exe。我还尝试使用编译代码g++ test.cpp -o test.exe。这并没有修复错误。
我之前在 Stack Overflow 上问过这个问题,但我未能得到清晰易懂的答案,很可能是因为我是一个完全的编程初学者。话虽这么说,有人可以给我一个答案,说明可能导致此问题的原因以及如何用简单的英语解决它吗?
当您将值"true"赋值给Java中的布尔数据类型(例如boolean variableName = true;)时,实际上为该变量分配了什么值?
我想使用 C 打印彩色文本。这是我的代码:
\n\n#include <stdio.h>\n\n#define ANSI_COLOR_RED "\\x1b[31m"\n#define ANSI_COLOR_GREEN "\\x1b[32m"\n#define ANSI_COLOR_YELLOW "\\x1b[33m"\n#define ANSI_COLOR_BLUE "\\x1b[34m"\n#define ANSI_COLOR_MAGENTA "\\x1b[35m"\n#define ANSI_COLOR_CYAN "\\x1b[36m"\n#define ANSI_COLOR_RESET "\\x1b[0m"\n\nint main()\n{\n char *string = "Test";\n\n printf("%s", ANSI_COLOR_RED string ANSI_COLOR_RESET);\n\n return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n编译时会输出错误:
\n\ngame.c:18:35: error: expected \xe2\x80\x98)\xe2\x80\x99 before \xe2\x80\x98string\xe2\x80\x99\nprintf("%s", ANSI_COLOR_RED string ANSI_COLOR_RESET);\n
Run Code Online (Sandbox Code Playgroud)\n\n我该如何修复这个错误?
\n