[英]why can't I work with strings in c++ vscode?
I am unable to run a code as simple as the following.我无法运行如下简单的代码。 Everything works fine if I am not working with strings.
如果我不使用字符串,一切正常。 I get an error-
exited with code=3221225785 in 2.131 seconds
.我
exited with code=3221225785 in 2.131 seconds
。 I've tried updating my MinGw compiler .我试过更新我的MinGw 编译器。 Does not work even if I use compile and run extension on vscode .
即使我在vscode上使用编译和运行扩展也不起作用。
#include<iostream>
#include<string>
int main()
{
std::string a="world";
std::cout<<a;
return 0;
}
it is really frustating to handle your systems setup, especially if you want to start to learn coding.处理您的系统设置真的很令人沮丧,特别是如果您想开始学习编码。 My rescue called: build system.
我的救援叫:构建系统。 I'm using cmake with this tutorial .
我在本 教程中使用cmake 。
But first thing first, for your special question, what you'll need are following workspace:但首先,对于您的特殊问题,您需要的是以下工作区:
working_directory
|--build/
|--src/test_code.cpp
|--src/CMakeLists.txt
with your code (I name it test_code.cpp
):使用您的代码(我将其命名为
test_code.cpp
):
#include<iostream>
#include<string>
int main()
{
std::string a="world";
std::cout<<a;
return 0;
}
and CMakeLists.txt
:和
CMakeLists.txt
:
cmake_minimum_required (VERSION 3.7)
project(testSomething)
add_executable(test test_code.cpp)
and run following in /build
directory:并在
/build
目录中运行以下命令:
> cmake ../src
> make
> ./test
Of course you'll need to install cmake first.当然,您需要先安装 cmake。 I think, directly using a build system in a tutorial helps you take care of your system setup, so usually those build system could find your installed compiler, linker etc. without you telling it explicitly.
我认为,在教程中直接使用构建系统可以帮助您处理系统设置,因此通常这些构建系统可以找到您安装的编译器 linker 等,而无需您明确告知。 (So its a kind of vodoo magic:)).
(所以它是一种巫毒魔法:))。
enter image description here在此处输入图像描述
I tried the same, but I'm getting proper results in the terminal.我尝试了同样的方法,但我在终端中得到了正确的结果。 I think you have not added 'mingw' to the environmental path.
我认为您没有在环境路径中添加“mingw”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.