[英]Qt: c++: how to read a “.dat” file
I have a ".dat" file that contains "1"s and "-1"s as a sequence in a vertical representation (ie: each element is in a single line.). 我有一个“.dat”文件,其中包含“1”和“-1”作为垂直表示中的序列(即:每个元素都在一行中)。
I am trying to read the file as follow: 我正在尝试阅读该文件如下:
char buf[30];
QFile sequence("Sequences.dat");
sequence.open(QFile::ReadOnly);
for(int sym=0; sym<29; sym++){
char c = symbols[sym] = sequence.readLine(buf,sizeof(buf));
symbols[sym] = c;
}
sequence.close();
however, the result is nothing like my sequence as seen below: 但是,结果与我的序列完全不同,如下所示:
what did I did wrong ? 我做错了什么?
Check the readLine
API doc: the return value is the number of bytes read, while the line is read into the buf
array, which is overwritten at each iteration. 检查readLine
API doc:返回值是读取的字节数,而行读入buf
数组,在每次迭代时都会被覆盖。 Note that the first symbol of the inspected array is a '\\0'
(empty string), probably because the last line of your file is empty. 请注意,被检查数组的第一个符号是'\\0'
(空字符串),可能是因为文件的最后一行是空的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.