在C+&#x2B中使用向量时,没有执行任何执行。使用VSCODE

发布于 2025-02-10 14:37:02 字数 874 浏览 1 评论 0 原文


我在C ++中的向量有问题。 当我尝试与他们一起做基本的事情时,我的程序“不再起作用”。

我尝试

在堆栈溢出上搜索但没有找到相关的内容。
但是我对这个话题不了解很多,所以我有点坚持下去。

一些代码:

示例:

#include <iostream>
#include <vector>

int main(int argc, char ** argv){
    std::cout << "Hello world\n";
    std::vector< int > arr;
}

此程序将输出“ Hello World”,因为我不与向量互动。
但是,如果我这样做:

#include <iostream>
#include <vector>

int main(int argc, char ** argv){
    std::cout << "Hello world\n";
    std::vector< int > arr;
    arr.push_back(1);

}

例如,没有Stdout。 Hello World永远不会“印刷”。而且没有错误。 我正在使用Visual Studio代码,并使用 G ++ -O Progam -wall main.cpp
当我在Visual Studio代码的“终端”上运行此操作时,它不起作用。但是,当我将其打入另一个外壳时,它会起作用。

The problem

I have a problem with Vector in C++.
When I try to do basic things with them, my program "doesn't works" anymore.

What I tried

Searching on Stack Overflow but didn't find something relevant.
But I don't know a lot on this topic so I'm kind of stuck with it.

Some code:

Example:

#include <iostream>
#include <vector>

int main(int argc, char ** argv){
    std::cout << "Hello world\n";
    std::vector< int > arr;
}

This program will outputs "Hello world" because I don't interact with the vector.
But if I do:

#include <iostream>
#include <vector>

int main(int argc, char ** argv){
    std::cout << "Hello world\n";
    std::vector< int > arr;
    arr.push_back(1);

}

for example, there is no STDOUT. Hello world is never "printed". And there are no errors.
I'm on Visual Studio code and I compile my program with
g++ -o progam -Wall main.cpp
When I run this on the "Terminal" of Visual Studio Code it doesn't works. But when I rut it on another shell it works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南风几经秋 2025-02-17 14:37:02

命令 g ++ -o -wall main.cpp 将创建一个可执行文件,称为 -wall 。除非您要运行的程序,否则它将无法正常工作。

取而代之的是,您需要 g ++ -o程序-Wall Main.cpp 之类的东西,然后运行 Program 。在这种情况下,您的两个示例都做对了。

The command g++ -o -Wall main.cpp will create an executable file called -Wall. Unless that's the program you're trying to run, it's not going to work.

Instead you would need something like g++ -o program -Wall main.cpp and then run program. Both of your examples do the right thing in that case.

你的背包 2025-02-17 14:37:02

我还遇到了这个问题(或非常相似的问题),其中VSCODE 1.72.2和G ++ 12.1.0。我的修复程序是将“ - static-libstdc ++”添加到 tasks.json 中的编译器参数中。

从跟踪这一点的一些额外的面包屑:
从VSCODE终端或PowerShell运行编译的程序似乎无能为力。从命令提示下执行它给出了一个弹出对话框:过程输入点_zst28__throw_bad_array_new_lengthv无法位于动态链接库中... google google for该搜索导致此线程其中@Thinker-101 给出了有用的编译器参数。

I also encountered this issue (or a very similar one) with VSCode 1.72.2 and g++ 12.1.0. My fix was to add "-static-libstdc++" to the compiler arguments in tasks.json.

Some extra breadcrumbs from tracking this down:
Running the compiled program from VSCode terminal or powershell quietly appeared to do nothing. Executing it from Command Prompt gave a popup dialog: The procedure entry point _ZSt28__throw_bad_array_new_lengthv could not be located in the dynamic link library ... Googling for that led to this thread where @Thinker-101 gave the helpful compiler argument.

拥抱影子 2025-02-17 14:37:02

您需要提及,在向量的情况下,正在使用哪种标准C ++。例如带有[代码]的文件名,因此要为使用向量的[代码]创建可执行文件,终端代码将为 g ++ -Std = C ++ 11 Code.cpp&amp;&amp; ./a.out 执行并运行代码

You need to mention, which standard is under use of c++ in the case of vectors. Such as a file name with [code], so to create an executable file for [code] with vectors , terminal code will be g++ -std=c++11 code.cpp && ./a.out to execute and run the code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文