Compile Error

I'm trying to compile my program, but I keep getting the error:


employee1.cc: In function ‘void Open()’:
employee1.cc:379:11: error: ‘stoi’ is not a member of ‘std’
employee1.cc:385:15: error: ‘stod’ is not a member of ‘std’
employee1.cc:387:12: error: ‘stoi’ is not a member of ‘std’


Here is the function that it is having issues with:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
void Open()
{
	string rfile;
	string temp;
	
	cout << "Enter a file name to read from (be sure to add extension, \".txt\" to the end and use no spaces): ";
	cin >> rfile;
	
	if(fexists(rfile.c_str()))
	{
		ifstream infile;
		infile.open(rfile.c_str());
		
		while(true)
		{
			if(infile.eof())
			{
				break;
			}
			getline(infile, temp, ';');
			a.ID = std::stoi(temp);
			getline(infile, temp, ';');
			a.fname = temp;
			getline(infile, temp, ';');
			a.lname = temp;
			getline(infile, temp, ';');
			a.salary = std::stod(temp);
			getline(infile, temp, ';');
			a.hpw = std::stoi(temp);
			getline(infile, temp, '\n');
			a.work = temp;
			ListEmployee.push_back(a);
		}
		
		cout << "Data has been read." << endl;
		infile.close();
		return;
	}
	else
	{
		cout << "File does not exist.  No data read from any file." << endl;
	}
}


How do I fix the error? I'm using Cygwin as a compiler.
Why are you using std:: infront of those ones it names? std:: is for the cout,cin, etc.

Basically it is saying those are not members of std::
To the OP: Have you forgotten to include <string> ?

To topherpunch: I'm fairly sure stoi etc are members of std. They're declared in <string>
According to http://www.cplusplus.com/reference/string/stoi/?kw=stoi it's part of std and yes, I did include <string>.
-std=c++11
Ah - I hadn't spotted the little symbol on the ref page to indicate it's C++11 only.
I tried doing -std=c++11, can you explain to me where to put that part within the compiler?
First, you should check whether your compiler even has any C++11 support.
how would I check cygwin for that?

I tried looking it up with no luck
You wouldn't. Cygwin isn't a compiler. What is your compiler? gcc?
gcc/g++ yeah
Well then, check the man pages for it.
upon searching, I believe that I discovered that it does not have c++11 installed. In case if I can't get this installed, how would I do what I want in the above code without using stoi?
C++11 isn't a thing you install - it's a standard that either is or isn't supported by your particular version of g++. The man pages for it should tell you what you need to know. If not, check which version of gcc you have and look online.
what is the best method to do so I could get the code to work?
Well, if the version of g++ that you're using supports C++11 - and you haven't said yet whether or not that's true - then just using the compiler option ne555 suggests will work.
yeah, that method didn't really work. I end up getting the same error message
Topic archived. No new replies allowed.