简体   繁体   English

为什么我不能在 c++ vscode 中使用字符串?

[英]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”。

enter image description here在此处输入图像描述

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

相关问题 我在 VSCODE C++ 中看不到警告/运行时错误 - I can't see warnings/ runtime errors in VSCODE C++ 我怎样才能让类论坛在 C++ 中使用字符串? - how can i make the class Forum work with strings in c++? 为什么我不能让运动显着性在 OpenCV C++ 中工作? - Why can't I get motion saliency to work in OpenCV C++? strcmp()可以在c ++中使用字符串吗? - Can strcmp() work with strings in c++? 我无法让 VSCode 在 c/c++ 文件的面包屑/大纲中显示 function 名称 - I can't get VSCode to show me function names in the breadcrumbs / outline in c/c++ files 为什么这些字符串不能在C ++中连接? - Why won't these strings concatenate in C++? C++ - 简单的 hello world 在 vscode 中不起作用 - C++ - Simple hello world doesn't work in vscode U +究竟是什么代表什么,为什么我不能在我的C ++应用程序中创建一个Unicode中间字符串表? - What exactly does U+ stand for and why can't I create a table of Unicode intermediate strings in my C++ application? 为什么即使在 c++ 中不包含字符串库,字符串有时仍然有效? - Why do strings still work sometimes even when you don't include the string library in c++? 为什么“ios::sync_with_studio(0) 和 cin.tie(0);” 不适用于 C++ 中的字符串 - Why "ios::sync_with_studio(0) and cin.tie(0);" doesn't work with strings in C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM