'stoi()' was not declared in this scope.

Jul 3, 2017 at 2:29pm
Hello!

I'm currently having an issue trying to compile a simple code in dev-C++.

I'm working with strings (#include <string> ) and want to convert a string into an int using stoi()

I've gone through my code several times and I don't think there is anything wrong with it.

However I have read about compilers and there might be an issue / incompatibility with mine.

For info I'm on windows 7 64 bit, using Dev-C++ version 4.9.9.1. The name of my compiler is "TDM-GCC 4.9.2 64 bit release".


Any help would be very much appreciated. Thanks in advance!



Here is my code, if needed:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <string>



using namespace std;

string getMonth(string);
void pause();


int main() 
{
	string date,
	       month,
	       day,
	       year;


	cout << "\n\n This program will ask you to enter the dat in the following\n"
	     << " format: mm/dd/yyyy.";

	cout << "\n\n\tEnter date:";
	getline(cin, date);


	month = date.substr(2,0);
	month = getMonth(month);

	day = date.substr(2,3);

	year = date.substr(4,6);

	date.clear();


	date = month;
	date.append(" ");

	date.append(day);
	date.append(", ");

	date.append(year);
	date.append(".");


	pause();


	return(0);
}

string getMonth(string m) 
{
	string months[12] = {"January", "February", "March", "April",
	                     "May", "June", "July", "August",
	                     "September","October", "November", "December"};

	int month;

	month = stoi(m);

	m = months[month];

	return(m);
}

void pause() 
{
	cout << "\n\nPress enter to continue...";
	cin. sync();
	cin.get();
	cout << "\n\n";


	return;
}
Jul 3, 2017 at 2:46pm
> The name of my compiler is "TDM-GCC 4.9.2 64 bit release".

Update to the current version of TDM-GCC (GCC 5.1.0); it has std::stoi

Otherwise for work-arounds, see:
http://www.cplusplus.com/forum/beginner/120836/#msg657958
http://www.cplusplus.com/forum/general/152105/#msg791139
Jul 3, 2017 at 2:46pm
closed account (E0p9LyTq)
Did you set your compiler options to use C++11?
Jul 3, 2017 at 3:06pm
Even TDM-GCC 4.9.2 has stoi.

Under Project->Project Options->Compiler->Code generation->Language standard choose C++11.
Jul 3, 2017 at 3:15pm
Did you set your compiler options to use C++11?


Unless I'm wrong, there doesn't seem to be such an option in Dev-C++, I've looked all around the place. Thank you for the advice nonetheless!


Update to the current version of TDM-GCC (GCC 5.1.0); it has std::stoi


Thank you for the advice, I'm trying to find out how to do that. I have found the package and downloaded it but I sill have to figure out how to import it to Dev-C++.
Jul 3, 2017 at 3:36pm
closed account (48T7M4Gy)
Aside from the problem with stoi() function, why is month in line 15 a string anyway? Seems to be complicated when an int does the job.
Jul 3, 2017 at 3:50pm
Aside from the problem with stoi() function, why is month in line 15 a string anyway? Seems to be complicated when an int does the job.



I use month as a string since I'm using user input to get the date in the following format: mm/dd/yyyy. month = date.substr(2,0);

I want to extract the two characters input for mm and convert them to int:
month = stoi(m);

then I would use month to get the corresponding month in the array
string months[12]

I'm doing all that in order to avoid writing 12 if loops such as
if(m == '1') { m = "January" } etc.
Jul 3, 2017 at 4:10pm
closed account (48T7M4Gy)
Yeah OK, I see. I won't divert you down the stringstream path as a workaround because it won't get you a stoi function which is solved directly by having the right compiler. :)
Jul 3, 2017 at 4:10pm
Yeah OK, I see. I won't divert you down the stringstream path as a workaround because it won't get you a stoi function which is solved directly by having the right compiler. :)


Thank you! Yes indeed I really want to stick to a stoi function on this one! :)


Well I've managed to download a separate package for TDM-GCC 5.1.0 but i can't get it to work on Dev-C++.

Do you guys have any recommendation as to what other program to use that supports c++11?


Thanks a lot anyway!
Last edited on Jul 3, 2017 at 4:13pm
Jul 3, 2017 at 4:43pm
other program to use that supports c++11: Visual Studio 2017 Community Edition
https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Community&rel=15

In the installer, select 'Desktop Development with C++'

In the summary pane on the right, select both:
'VC++ 2017 v141 toolset' (the microsoft compiler and tool-chain ) and
'Clang/C2' (the clang++ frontend)

That is all that you need. For a lighter download and installation, uncheck everything else.
Jul 3, 2017 at 4:50pm
Thank you a lot JLBorges I will look into Visual Studio!
Jul 3, 2017 at 5:40pm
Yeah OK, I see. I won't divert you down the stringstream path as a workaround because it won't get you a stoi function which is solved directly by having the right compiler. :)

Seems nobody was reading my post. TDM-GCC 4.9.2 has stoi
Jul 4, 2017 at 1:35am
closed account (48T7M4Gy)
I will look into Visual Studio
An excellent move if you can. They've even got a version for OSX via XCode which makes it even better.
Jul 4, 2017 at 4:06am
Seems nobody was reading my post. TDM-GCC 4.9.2 has stoi

Thomas: don't get disheartened, sometimes in our electronic tower of Babel even valuable suggestions get overlooked. You're one of the most thoughtful commentator and observer on the forum, so it's the OP's loss if s/he doesn't read carefully.
Jul 4, 2017 at 10:49am
Thanks gunnerfunner.
Topic archived. No new replies allowed.