在QT中声明StringStream问题
我在 QT 中声明 StringStream 时遇到问题。 这是我的代码:
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;
错误消息是:
aggregate 'std::stringstream ss' has incomplete type and cannot be defined;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
混合
QString
和std::string
或相关内容通常不是一个好主意。您应该使用QString
方法来实现,例如replace( QChar ch, const QString & after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
。顺便说一句,您不能直接将 QString 与任何标准
std
流一起使用,没有定义重载。不过,qPrintable
函数可以提供帮助。并且您需要包含
才能使用std::stringstream
。Mixing
QString
andstd::string
or related is not generally a good idea. You should implement that withQString
methods likereplace( QChar ch, const QString & after, Qt::CaseSensitivity cs = Qt::CaseSensitive)
.BTW, you can't use QString directly with any of the standard
std
streams, there are no overloads defined. TheqPrintable
function can help though. And you need to include<sstream>
to usestd::stringstream
.包含
以使用stringstream
类。尽管我确实同意 @Mat 的观点,但使用 Qt 的 QString 方法来实现此特定目的可能是一个好主意。
Include
<sstream>
to use thestringstream
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.