[英]String variables don't work in Eclipse CDT
When I use string variables in Eclipse CDT (MinGW compiler) and I run the program, it doesn't show me anything. 当我在Eclipse CDT(MinGW编译器)中使用字符串变量并运行该程序时,它什么都没有显示。 Here's my code: 这是我的代码:
#include <iostream>
using namespace std;
int main() {
string hw = "Hello, world!";
cout << hw << endl;
return 0;
}
So that doesn't show anything, but when I just do cout << "Hello, world!" 所以那什么都没显示,但是当我只是喊着<<“你好,世界!” << endl; << endl; it does work. 它确实有效。
I also tried including <string>
, <string.h>
, "string"
and "string.h"
but still no success. 我也尝试包括<string>
, <string.h>
, "string"
和"string.h"
但是仍然没有成功。 The same code does work in VC++ and Codeblocks though. 相同的代码在VC ++和代码块中确实起作用。
I can reproduce this problem on my machine. 我可以在机器上重现此问题。 The output does not appear. 输出不会出现。 But it is not an output problem, but actually two problems before you get to main: 但这不是输出问题,但在进入main之前实际上是两个问题:
The program can't start because libgcc_s_dw2-1.dll is missing from your computer. 该程序无法启动,因为您的计算机缺少libgcc_s_dw2-1.dll。 Try reinstalling the program to fix this problem. 尝试重新安装该程序以解决此问题。
Screenshot of above: 上面的屏幕截图:
You need to get the environment correctly set up to launch the MinGW program because its DLLs are not installed on Windows PATH or other standard places DLLs are searched for. 您需要正确设置环境以启动MinGW程序,因为它的DLL未安装在Windows PATH或搜索DLL的其他标准位置上。
C:\\MinGW\\bin
to your PATH
将C:\\MinGW\\bin
添加到PATH
If your program compiles, as I am sure it does based on your comments, changing the includes is probably irrelevant. 如果您的程序可以编译,就像我确信它是根据您的注释那样编译的,则更改包含可能无关紧要。
By adding an infinite loop around the cout
s I could immediately identify something more than simply an output not being shown was going on. 通过在cout
周围添加无限循环,我可以立即识别出一些内容,而不仅仅是发生未显示的输出。 Try the same thing on your machine, and also try running the program from within MinGW shell and from outside it. 在您的计算机上尝试同样的事情,还尝试从MinGW shell内部和外部运行程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.