gpt4 book ai didi

c++ - 如何弹出 QString 的第一个字符串?

转载 作者:行者123 更新时间:2023-11-30 04:03:44 25 4
gpt4 key购买 nike

例如,我的QString"12 1,2 3,4",我想弹出"12"然后可能会删除前导空格,使其变为 "1,2 3,4"

这是从输入文件读取的一部分。

QFile input_file("path/to/testfile.txt");

if (!input_file.exists()) {
dbg << "File does NOT exist" << endl;
exit(1);
}

if (!input_file.open(QFile::ReadOnly)) {
exit(2);
}

QDataStream input_stream(&input_file);
while (!input_file.atEnd()) {
QString line = input_stream.readLine();
// how do I parse off that first number?

最佳答案

看起来像QTextStream会完成这项工作,您的评论当前所在的位置。

QTextStream 似乎是 std::istringstream 的 QT 等价物,旨在解析由空格分隔的文本。

QTextStream text_stream( &line );
QString that_first_numer;

text_stream >> that_first_number; // Read text up to whitespace
line = text_stream.read_line(); // Copy the remaining text back to line.

关于c++ - 如何弹出 QString 的第一个字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24225992/

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