“To_string ‘was not declared in this scope” is sometimes encountered when using CodeBlocks (the compiler adopts MinGW) under windows Code blocks, to_ String and so on, which only introduces the parts and solutions related to this problem
first, to_String is a new function introduced by C + + 11, which may not be supported by the old compiler, so “C + + 11” compilation support should be added to the compiler: open Settings -> Compiler
Check the C + + 11 standard here
of course, you should also check your code for problems. to_String is contained in string, and string is contained in space STD, so your code should include header file and related space introduction, for example:
#include <iostream> #include <string> //std::string std::to_string using namespace std; int main() { int a = 123; cout << "a = " << to_string(a) <<endl; // If you don't add namespaces you can use std::to_string here return 0; }