0

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.

#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?

1 Answers1

0

Some years ago when I was using MinGW, I got exactly the same kind of problem as you did. Whenever the code used any C++ standard library function, it could compile, but could not run.

The problem was due to libstdc++ being installed incorrectly. A quick fix is to add -static-libstdc++ to your compiler option. However, to fully resolve the issue you have to reinstall your compiler and standard library.

user2249675
  • 464
  • 3
  • 13
  • Thanks! I will try this tomorrow as soon as possible, because this is not the first time I got this kind of problem. Maybe it will fix my other programs too, as there are alot of weird things like this happening and I am sick of it. Thanks alot! – Lucas Knook Apr 30 '18 at 20:47
  • well, I tried the quick fix, but it doesn't seem to work, I am using visual studio code, in the user settings it now says this:{ "code-runner.runInTerminal": true, "clang.cxxflags": ["-static-libstdc++"] } – Lucas Knook May 01 '18 at 09:11
  • what do you mean with reinstalling compiler and standard library? Reinstalling minGW? or do I have to download from somewhere else? – Lucas Knook May 01 '18 at 09:12
  • I use gcc. -static-libstdc++ is a gcc specific option, requiring the compiler to link libstdc++ at compile time, instead of run time. I don't know about the corresponding command for clang. – user2249675 May 01 '18 at 14:26
  • Delete the whole MinGW folder, and run the installer again should work. – user2249675 May 01 '18 at 14:28