//获取文件路url
//开始对文件内容比较
fin.open(url);
int count= 0;
char c = 9;
while(fin.eof()==0)
{
fin>>c;
if(c == ',')
count =+;
}
在编辑框里显示count我的思路是在界面里获得了文件路径以后,用ifstream的方法逐个比较。但是在调试的时候发现while进入了一个死循环。求解。我写了一个控制台的程序,没有问题。
#include<iostream>
using namespace std;
#include<fstream>
#define URL "text.txt"
int main()
{
ifstream fin;
fin.open(url);
int i = 0;
char c = 9;
while(fin.eof()==0)
{
fin>>c;
if(c == ',')
i++;
}
cout<<"i = "<<i<<endl;
}来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2349/viewspace-3164040/ ,如需转载,请注明出处,否则将追究法律责任。