繁体   English   中英

QString::toInt() 如何转换非数字的字符串?

[英]How can QString::toInt() convert a string that's not numeric?

我正在阅读我的一本教科书,它在解释它引入的代码方面做得很差。 这里的示例代码:

int choice;
QString response;
do {
 cout << READ << ". Read data from a file.\n"
 << ADD << ". Add items to the Library.\n"
 << FIND << ". Find and display an item.\n"
 << REMOVE << ". Remove an item from the Library.\n"
 << SAVE << ". Save the Library list to a file.\n"
 << LIST << ". Brief listing of Library items.\n"
 << QUIT << ". Exit from this program.\n"
 << "Your choice: " << flush;
 response = cin.readLine();
 choice = response.toInt();
} while(choice < READ or choice > QUIT)

根据QT 文档

如果转换失败,则返回 0。

这意味着,如果字符串不是数字,它将返回 0。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM