Getline was not declared in this scope chữa lỗi năm 2024

even though that was not how getline was called when it worked. Here are my errors. I am not sure what they mean:

prog1.cpp:89: error: no matching function for call to ‘std::basic_istream<char, std::char_traits<char> >::get(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, const char&)’

/usr/include/c++/4.1.3/istream:286: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::get(_CharT&) [with _CharT = char, _Traits = std::char_traits]

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; }

Did you set your compiler options to use C++11?

Even TDM-GCC 4.9.2 has stoi.

Under Project->Project Options->Compiler->Code generation->Language standard choose C++11.

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++.

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.

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.

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. :)

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

other program to use that supports c++11: Visual Studio 2017 Community Edition //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.

Thank you a lot JLBorges I will look into Visual Studio!

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

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.

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.

Chủ đề