简体   繁体   English

使用cout打印字符串数组不起作用

[英]using cout to print an string array not working

I have this code, which is supposed to cout an string of an array, but it doesn't do anything :/ also, when I run the .exe file itself it gives some errors of not finding basic_string in the file. 我有这段代码,应该找出一个数组的字符串,但是它什么也没做:/而且,当我运行.exe文件本身时,它会给出一些在文件中找不到basic_string的错误。

#include <iostream>
#include <string>
using namespace std;

//red is F-face, yellow is D-face
//B G O R W Y

class cube{
    public:
        string cubeCorners[8] = {"BOY", "GOY", "GRY", "BRY", "BOW", "GOW", "GRW", "BRW"};

        void U(){
            cout << cubeCorners[1];
            cubeCorners[2] = cubeCorners[3], cubeCorners[6] = cubeCorners[2], cubeCorners[7] = cubeCorners[6], cubeCorners[3] = cubeCorners[7];
        }
};

int main(){
    cube obj;
    obj.U();
    return 0;
}

How do I fix this, and what did I do wrong? 我该如何解决?我做错了什么?

Some years ago when I was using MinGW, I got exactly the same kind of problem as you did. 几年前,当我使用MinGW时,遇到的问题与您完全一样。 Whenever the code used any C++ standard library function, it could compile, but could not run. 每当代码使用任何C ++标准库函数时,它都可以编译,但无法运行。

The problem was due to libstdc++ being installed incorrectly. 该问题是由于libstdc ++安装不正确引起的。 A quick fix is to add -static-libstdc++ to your compiler option. 一个快速修复是将-static-libstdc++添加到您的编译器选项中。 However, to fully resolve the issue you have to reinstall your compiler and standard library. 但是,要完全解决该问题,您必须重新安装编译器和标准库。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM