简体   繁体   English

C++ - 简单的 hello world 在 vscode 中不起作用

[英]C++ - Simple hello world doesn't work in vscode

I've just started programming in c++ and I've a problem that is probably really simple but I've been trying to solve it for a long time.我刚刚开始在 c++ 中编程,我遇到的问题可能非常简单,但我已经尝试解决了很长时间。 Cout prints all built-in variables but when I try to print a string variable, it doesn't work (it doesn't print anything even if there are other couts with other things to print that aren't strings). Cout 打印所有内置变量,但是当我尝试打印字符串变量时,它不起作用(即使有其他 cout 和其他非字符串要打印的东西,它也不会打印任何东西)。

In short, when there's a string variable in the code, nothing works , at least that is what I noticed.简而言之,当代码中有一个字符串变量时,什么都不起作用,至少这是我注意到的。

That doesn't print anything那不打印任何东西

#include <iostream>
#include <string>
using namespace std;

int main() {
    string greeting="hello";
    cout << greeting;
    }

But that works:但这有效:

    cout << "hello"; 

I've tried the same exact code in online editors and it does work.我在在线编辑器中尝试过相同的代码,它确实有效。

EDIT 1:编辑1:

In the computer's terminal, this is what is shown: procedure entry point is not found... in the dinamic link library...在计算机的终端中,显示如下:在动态链接库中找不到过程入口点...

Path: This is the mingw path: C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin路径:这是 mingw 路径:C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin

EDIT 2编辑 2

Finally solved it.终于解决了。 I've copied the libstdc++ and the libgcc to where I have the.exe.Thank you all for your support.我已将libstdc++libgcc复制到我拥有 .exe 的位置。谢谢大家的支持。 Special thanks to @HolyBlackCat.特别感谢@HolyBlackCat。

The solution to errors like "procedure entry point is not found" is: “找不到过程入口点”等错误的解决方案是:

  • Make a list of all .dll s located in your compiler's bin directory.列出所有位于编译器bin目录中的.dll

  • Go through C:\Windows and C:\Windows\System32 and make sure none of those dlls are there. Go 到C:\WindowsC:\Windows\System32并确保这些 dll 都不存在。 If you find any, move them somewhere else (or delete them).如果您发现任何东西,请将它们移到其他地方(或删除它们)。

  • Add your compiler's bin directory to the PATH , as the first entry.将编译器的bin目录添加到PATH中,作为第一个条目。

I should see the whole code, but considering it doesn't work only with a string , probably you didn't use the namespace std : Try this:我应该看到整个代码,但考虑到它不仅仅适用于string ,可能你没有使用namespace std :试试这个:

#include <iostream>

using namespace std;

int main()
{
    string greeting = "Hello";

    cout << greeting;
}

If it doesn't work, show me the whole code and I'll see if I can help!如果它不起作用,请向我展示整个代码,我会看看我是否可以提供帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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