string s;
while(s!="#")
{
cout<<"Please input a chinese sentence:";
cin>>s;
sentence=QString::fromStdString(s).toLocal8Bit();
qDebug()<<sentence.size();
}
RT,但是中文长度总是不正确
4 个解决方案
#1
sentence = QString::fromLocal8Bit(str.c_str());试一下
#2
QString::size();返回的才是字符个数
#3
你把QString转成了string干什么,多此一举
直接用QString::size()就是了
直接用QString::size()就是了
#4
string s;
QString sentence;
while(s!="#")
{
cout<<"Please input a chinese sentence:";
cin>>s;
sentence=QString::fromStdString(s);
qDebug()<<sentence.toLocal8Bit().size();
}
#1
sentence = QString::fromLocal8Bit(str.c_str());试一下
#2
QString::size();返回的才是字符个数
#3
你把QString转成了string干什么,多此一举
直接用QString::size()就是了
直接用QString::size()就是了
#4
string s;
QString sentence;
while(s!="#")
{
cout<<"Please input a chinese sentence:";
cin>>s;
sentence=QString::fromStdString(s);
qDebug()<<sentence.toLocal8Bit().size();
}