Reputation: 732
I am having problem in declaring StringStream in QT. Here is my code:
std::stringstream ss;
for (int i = 0; i <= path.length()-1; ++i)
{
if (path[i] == '\\')
{
ss << "\\\\";
}
else
{
ss << path[i];
}
}
path = QString::fromStdString(ss.str());//store the stringstream to a string
return path;
the error message is:
aggregate 'std::stringstream ss' has incomplete type and cannot be defined;
Upvotes: 0
Views: 7585
Reputation: 206861
Mixing QString
and std::string
or related is not generally a good idea. You should implement that with QString
methods like replace( QChar ch, const QString & after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
.
path.replace('\\', "\\\\");
BTW, you can't use QString directly with any of the standard std
streams, there are no overloads defined. The qPrintable
function can help though. And you need to include <sstream>
to use std::stringstream
.
Upvotes: 3
Reputation: 7125
Include <sstream>
to use the stringstream
class.
Though I do agree with @Mat that it would probably be a good idea to use Qt's QString methods for this particular purpose.
Upvotes: 2