如何检查文件中的最后一个字符? [英] How Do I Check Last Character In File ?

查看:172
本文介绍了如何检查文件中的最后一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我想检查输入文件如:if ch == if语句输入文件中的最后一个字符。我怎么能这样做。 in C ++

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++

while(!inputFile.eof())
	 {
 inputFile.get(my_character);
if(myquestion)
{
.....
}



我做了


I did

while(inputFile >> character_count)
	{
		character__count++;
	}



然后我还有另一个while循环


and then also I have another while loop

while(inputFile.get(ch))
{
count++;

if(count==character__count++)

{
do something
}
}



所以我做了这个,但我想要不同的解决方案如何使用ifstream检查这个classes


So I did this but I want different solution how can I check this by using ifstream classes

推荐答案

基于理查德的建议:

请看:http://whitefirer.org/cplusplus.fuction/reference/iostream/istream/seekg.html [ ^ ]

该示例调用 seekg(0,ios :: end); 你应该用-1而不是0来调用
seekg( 0,ios :: beg )返回文件的开头并开始处理。
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.


这篇关于如何检查文件中的最后一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆