getting last few of lines of data from txt file

hi,

this is my .txt file.

Read RMS voltage Register!
00980C7E
0.5939
Actual voltage!
237.5762
Read RMS current Register!
0002AEE6
0.0104
Actual current!
0.0873
Read status Register!
007FC3BC
Read RMS voltage Register!
009805E8
0.5938
Actual voltage!
237.5360
Read RMS current Register!
0002AF74
0.0104
Actual current!
0.0874
Read status Register!
007FC2D6
Read RMS voltage Register!
0097F7F8
0.5936
Actual voltage!
237.4509 ---------------------------> (i need this value)
Read RMS current Register!
0002ACE0
0.0104
Actual current!
0.0870 ------------------------> (i need this value)
Read status Register!
00920089



how do i write a c++ program to get the values?

as this text file kept updating, i need to always get the newest value (which values are insert at the bottom) will it affect the updating of the text file?

sry noob here...
Read the whole file line by line until you find line "Actual voltage!" then read and analyze the next line (it will contain voltage value). The same story is with the current.

PS to read line use getline(inputStream, inputString);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
string str_line, strTemp[50];
	int count = 0 ; 
	ifstream inputfile ( "example.txt" ) ; 

	if(inputfile.is_open() ) 
	{
		while( inputfile.good() ) 
		{
			inputfile>>str_line ; 
			if( isdigit(str_line) ) 
			{
				strTemp[count] ; 
				count++; 
			}
		}
	}
but i needed the latest values, which is always at the bottom of the text file, so i needed to read the whole text file?

any sample code for me to refer to?
yes you need to read the whole file ..
Well, technically you don't have to read the entire file, you just have to start reading somewhere before the information you want is found.

If we can assume the worst size values for the floating point numbers, we can say that we need to seek to somewhere around 150-160 bytes (characters) before the end of the file, and start reading lines from there.

When you encounter a line that reads "Actual voltage!" then you know that the very next line will contain the voltage value you want, and likewise for the lines that start with "Actual current!". Once you get both of those, you are done.

Hope this helps.
Topic archived. No new replies allowed.