在C+&#x2B中使用向量时,没有执行任何执行。使用VSCODE
我在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代码的“终端”上运行此操作时,它不起作用。但是,当我将其打入另一个外壳时,它会起作用。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
命令
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 runprogram
. Both of your examples do the right thing in that case.我还遇到了这个问题(或非常相似的问题),其中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 intasks.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.您需要提及,在向量的情况下,正在使用哪种标准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