简体   繁体   English

字符串变量在Eclipse CDT中不起作用

[英]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之前实际上是两个问题:

  1. The program is failing to launch. 该程序无法启动。 If you try double-clicking on it in Windows Explorer, you will get an error message like this: 如果尝试在Windows资源管理器中双击它,将收到以下错误消息:

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: 上面的屏幕截图:

上面引用的错误的屏幕截图

  1. When launched from within Eclipse, this error message is silently swallowed, so how are you supposed to know! 从Eclipse中启动时,此错误消息会被静默吞下,因此您应该怎么知道!

Solutions/Workarounds 解决方案/解决方法

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的其他标准位置上。

  1. Add C:\\MinGW\\bin to your PATH C:\\MinGW\\bin添加到PATH
  2. Launch Eclipse from within a MinGW shell (has basically same effect as 1) 从MinGW shell中启动Eclipse(效果与1基本相同)
  3. Run the program in debug mode, this causes the program to be launched as a child of GCC and that sets up 在调试模式下运行程序,这将导致程序作为GCC的子级启动并进行设置
  4. Other options (not tried by me) may include statically linking the offending library, see The program can't start because libgcc_s_dw2-1.dll is missing 其他选项(我没有尝试过)可能包括静态链接问题库,请参阅程序丢失,因为libgcc_s_dw2-1.dll丢失
  5. File a CDT bug about the error message being hidden. 提交有关隐藏错误消息的CDT错误

Extra info 额外信息

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM