how to use std::getline(std::cin, s);
-
wrote on 19 Jul 2020, 22:40 last edited by Natural_Bugger
I'm trying to build some console application using "example" code.
i have been looking online and it looks correct.
http://www.cplusplus.com/reference/string/string/getline/but it does not work or compile in Qt creator:
QString s; std::getline(std::cin, s);
error:
main.cpp:34: error: no matching function for call to ‘getline(std::istream&, QString&)’ 34 | std::getline(std::cin, s); | ^
how to solve?
regards.
-
@Natural_Bugger said in how to use std::getline(std::cin, s);:
how to solve?
By reading the documentation of std::getline(): 'Defined in header <string>'
-
I'm trying to build some console application using "example" code.
i have been looking online and it looks correct.
http://www.cplusplus.com/reference/string/string/getline/but it does not work or compile in Qt creator:
QString s; std::getline(std::cin, s);
error:
main.cpp:34: error: no matching function for call to ‘getline(std::istream&, QString&)’ 34 | std::getline(std::cin, s); | ^
how to solve?
regards.
std::getline()
knows aboutstd::string
but it doesn't know aboutQString
. So, store your input in a std::string first and then callQString::fromStdString()
.
1/3