to_string not declared in scope

前端 未结 6 784
[愿得一人]
[愿得一人] 2020-12-15 05:16

I am trying to make the to_string(NUMBER) function work in my Ubuntu computer for weeks but it never ever works in the QT environment or anywhere else. My code

相关标签:
6条回答
  • 2020-12-15 05:47
    //Try this if you can't use -std=c++11:-
    int number=55;
    char tempStr[32] = {0};
    sprintf(tempStr, "%d", number);
    
    0 讨论(0)
  • 2020-12-15 05:48

    you must compile the file with c++11 support

    g++ -std=c++0x  -o test example.cpp
    
    0 讨论(0)
  • 2020-12-15 05:53

    There could be different reasons why it doesn't work for you: perhaps you need to qualify the name with std::, or perhaps you do not have C++11 support.

    This works, provided you have C++11 support:

    #include <string>
    
    int main()
    {
      std::string s = std::to_string(42);
    }
    

    To enable C++11 support with g++ or clang, you need to pass the option -std=c++0x. You can also use -std=c++11 on the newer versions of those compilers.

    0 讨论(0)
  • 2020-12-15 05:57

    You need to make some changes in the compiler. In Dev C++ Compiler: 1. Go to compiler settings/compiler Options. 2. Click on General Tab 3. Check the checkbox (Add the following commands when calling the compiler. 4. write -std=c++11 5. click Ok

    0 讨论(0)
  • 2020-12-15 06:01

    This error, as correctly identified above, is due to the compiler not using c++11 or above standard. This answer is for Windows 10.

    For c++11 and above standard support in codeblocks version 17:

    1. Click settings in the toolbar.

    2. A drop-down menu appears. Select compiler option.

    3. Choose Global Compiler Settings.

    4. In the toolbar in this new window in second section, choose compiler settings.

    5. Then choose compiler flags option in below toolbar.

    6. Unfold general tab. Check the C++ standard that you want your compiler to follow.

    7. Click OK.

    For those who are trying to get C++11 support in Sublime text.

    1. Download mingw compiler version 7 or above. In versions below this, the default c++ standard used is c++98 whereas in versions higher than 7, the default standard used is c++11.

    2. Copy the folder in main C drive. It should not be inside any other folder in C drive.

    3. Rename the folder as MinGW. This name is case insensitive, so it should any variation of mingw and must not include any other characters in the name.

    4. Then go to environment variables and edit the path variable. Add this "C:\mingw\bin" and click OK.

    5. You can check the version of g++ in cmd by typing g++ -v.

    6. This should be sufficient to enable c++11 in sublime text.

    If you want to take inputs and outputs as well from input files for competitive programming purposes, then follow this link.

    0 讨论(0)
  • 2020-12-15 06:02

    I fixed this problem by changing the first line in Application.mk from

    APP_STL := gnustl_static
    

    to

    APP_STL := c++_static
    
    0 讨论(0)
提交回复
热议问题