Momergil
18th July 2011, 16:05
Hello!
I have the need of creating a software that is capable of reading lines from a text (let us say, from a .txt file) in pre-programmed blocks and saving them in a list of strings.
So, for example, here is the first line of the cput-stat file of my PC:
cpu 345652 7067 100651 5176702 20949 2797 1185 0 0
Imagine that I'm trying to read this first line (which is what I'm actually trying, for tests). But I don't want to read the entire line directly; i want to read just the "cpu" part. In this case, I would use the Qt function "readLine(3)" as a way of doing it
But what if I want to read only the second column? [345652] How can I say in a function that I want to read from bit 6 to 12 only and save it in a string without the rest of the line?
If I'm not confusing things, when I began learning C++ in the university my professor show me a function, in C++, that one could use to read a line and stop reading when a empty space appear. If that is correct, than I could use a series of this function in order to read all of the column, save thoose that I want and discard the undesireble ones.
The problem is: I don't know anymore the code for that function.
So my question is: how can I read, ether with C++ or Qt codes, delimited blocks of data in a line of text?
I would be glad if someone could give me a code example for that.
Thanks!
I have the need of creating a software that is capable of reading lines from a text (let us say, from a .txt file) in pre-programmed blocks and saving them in a list of strings.
So, for example, here is the first line of the cput-stat file of my PC:
cpu 345652 7067 100651 5176702 20949 2797 1185 0 0
Imagine that I'm trying to read this first line (which is what I'm actually trying, for tests). But I don't want to read the entire line directly; i want to read just the "cpu" part. In this case, I would use the Qt function "readLine(3)" as a way of doing it
But what if I want to read only the second column? [345652] How can I say in a function that I want to read from bit 6 to 12 only and save it in a string without the rest of the line?
If I'm not confusing things, when I began learning C++ in the university my professor show me a function, in C++, that one could use to read a line and stop reading when a empty space appear. If that is correct, than I could use a series of this function in order to read all of the column, save thoose that I want and discard the undesireble ones.
The problem is: I don't know anymore the code for that function.
So my question is: how can I read, ether with C++ or Qt codes, delimited blocks of data in a line of text?
I would be glad if someone could give me a code example for that.
Thanks!