Error implicit declaration of function "int to_string()"

We developed a tic-tac game in our class and for some reason I keep getting error when I run the program and I don't know how to overcome it!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
#include <cstdlib>

using namespace std;

const int SIZE = 3;

void displayBoard(string b[][SIZE]);
bool userFirst();
bool currentPlayerWon(string b[][SIZE], string symbol);

int main() {
	//construct board
	string board[SIZE][SIZE];

	int position_id = 1;
	for (int i = 0; i< SIZE; i++) {
		for (int j = 0; j < SIZE; j++) {
			board[i][j] = to_string(position_id);
			/*  stringstream ss;
			ss << position_id;
			board[i][j] = ss.str();
			*/position_id++;
		}
	}


I'm using cygwin g++ compiler and it says sstream isn't a recognizable library, and when I comment out sstream inorder to use to_string, I'm getting "Implicit declaration of function "int to_string()" error! If this error is related to the outdated compiler I'm using, then can somebody link me to an optimal version!?
it says sstream isn't a recognizable library

When you need to ask about errors, always post them verbatim. This helps others find your post, eliminates the risk of the poster misinterpreting it, and might jog the memory of people who have encountered the error before you.

<sstream> has been available since C++98. It is unlikely that your compiler does not support any version of standard C++. First, edit your post to include the errors you got, and then please issue g++ --version | head -1 at your Cygwin shell, put the results here. This will tell you the version of g++ you are using.

std::to_string() is available as part of C++11 and later, as part of <string>, not <sstream>.

For compiler versions in the 4.3.x series or later, you should be able to get at least some C++11 support by compiling with the appropriate flag. As for 6.x.x (as of now, the latest version is 6.2.1), C++11 support (with some extensions) is enabled by default.

For compiler versions in [4.3.0, 4.7.0), you should be able to pass the flag -std=c++0x to the compiler for preliminary support of C++11.
For compiler versions starting at 4.7.0, you should be able to enable (at least partial) support for C++11 by passing the flag -std=c++11 to the compiler.

It's usually worth updating your compiler because most of the changes are bug-fixes. Your compilers are tested heavily by the developers - and while you are relatively unlikely to encounter a compiler bug in stable releases as an end user, it will suck badly if you do. (I don't know how to update Cygwin installations. The newest version of G++ is available from https://gcc.gnu.org/svn.html .)
Last edited on
Topic archived. No new replies allowed.