Reputation: 63
Using the default str() example from: http://www.cplusplus.com/reference/sstream/stringstream/str/
// stringstream::str
#include <string> // std::string
#include <iostream> // std::cout
#include <sstream> // std::stringstream, std::stringbuf
int main () {
std::stringstream ss;
ss.str ("Example string");
std::string s = ss.str();
std::cout << s << '\n';
return 0;
}
The code helper is saying str()
could not be resolved, when building there is no errors related to str()
I have CDT GCC Built-in Compiler Settings
on in Eclipse
And unchecked use global provider with the flags:
"${COMMAND} ${FLAGS} -E -P -v -dD -std=c++11 "${INPUTS}"
I also tried changing toolchains back and forth but no luck.
Upvotes: 1
Views: 1599
Reputation: 201
The problem is somehow caused by the structure of the g++ header files. In header <sstream>
there are only the 'basic' template classes defined. I had the same error with a ostringstream
when calling the str()
method.
When I changed the variable type in my code to std::basic_ostringstream<char>
, the error went away. Also autocompletion worked again (it didn't work before, which is a good sign that the eclipse scanner is somehow having problems). Of course this is not a real good solution, because it uses the basic_* type, but it is one to get rid of the (harmless) error. The typedefs for the 'official' types like ostringstream
are forward-declared in the header <iosfwd>
.
When I include a typedef (in the global namespace) in my code after the standard include files:
typedef std::basic_ostringstream<char> ostringstream;
and use this type ostringstream
instead of std::ostringstream
, the error also goes away. So the problem is caused by the forward declarations in the standard header file <iosfwd>
(which does not mean that these headers a wrong, simply the eclipse scanner is puzzeled by this).
I am using g++ (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609 btw.
Upvotes: 1