【问题标题】:g++/MSYS64/Mingw64/VS Code compilation problemsg++/MSYS64/Mingw64/VS代码编译问题
【发布时间】:2022-06-24 00:34:28
【问题描述】:

在 VS Code 中使用 g++ 编译器时,使用 MSYS64 和 g++ 12.1.0,我可以编译一个基本的 hello world 程序,但是一旦我引入带有向量的代码并且我想象其他标准 C++ 库,程序就会编译,输出为空白。如果我转到过去构建的 g++/MSYS64/Mingw64 构建 (g++ 10.3.0) 标准库工作,我会使用 cout 从向量中获取输出。我想知道是否有其他人有这个问题以及如何解决它?

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    cout << "Hello World" << endl;
    string test = "test String, test vector"; 
    // if I comment out vector related code output works with cout

    vector<string> testVec(2);

    testVec.at(0) = test;
    testVec.at(1) = test;

    
    cout << testVec.at(0) << testVec.at(1) << endl;

    vector<string> msg{"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    for (const string &word : msg)
    {
        cout << word << " ";
    }

    return 0;

}

【问题讨论】:

  • 尝试从 mingw64 shell 运行你编译的程序。也尝试刷新输出流

标签: c++ visual-studio-code g++ mingw-w64 msys2


【解决方案1】:

它似乎在 mingw64 shell 中工作。

【讨论】:

    猜你喜欢
    • 2013-06-25
    • 2022-01-09
    • 1970-01-01
    • 2015-11-05
    • 2012-05-07
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多