Declaring StringStream in QT Problem
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;
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
.
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.
精彩评论