gpt4 book ai didi

c++ - QString::toInt()如何转换非数字字符串?

转载 作者:行者123 更新时间:2023-12-02 10:18:18 25 4
gpt4 key购买 nike

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

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 Documentation

Returns 0 if the conversion fails.



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

关于c++ - QString::toInt()如何转换非数字字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61169046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com