Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello everyone

I want to check input file like : if ch==the last character in input file in if statement.How can I do that. in C++
C++
while(!inputFile.eof())
	 {
 inputFile.get(my_character);
if(myquestion)
{
.....
}

I did
C++
while(inputFile >> character_count)
	{
		character__count++;
	}

and then also I have another while loop
C++
while(inputFile.get(ch))
{
count++;

if(count==character__count++)

{
do something
}
}

So I did this but I want different solution how can I check this by using ifstream classes
Posted
Updated 16-Nov-15 8:20am
v3
Comments
ZurdoDev 16-Nov-15 12:55pm    
Where are you stuck?
Sergey Alexandrovich Kryukov 16-Nov-15 13:06pm    
It depends on what else to read from this file. I mean, depending on that, you can choose more or less redundant implementation. It seems to be simple, but we need to know what have you tried so far.
—SA
Richard MacCutchan 16-Nov-15 13:42pm    
Seek to the end-1 and read the next character.
Member 12137990 16-Nov-15 14:08pm    
Can you give me a specific code example Richard ?
Richard MacCutchan 16-Nov-15 15:56pm    
Come on, look at the seek() function, it's not exactly complicated.

1 solution

Based on Richard's advice:
Look at: http://whitefirer.org/cplusplus.fuction/reference/iostream/istream/seekg.html[^]
Where that example calls seekg(0, ios::end); you should call with -1 instead of 0
Then read the last character, then seekg(0, ios::beg) to go back to the beginning of the file and start your processing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900