ITPub博客

首页 > > > 写一个MFC程序,选择了一个文本文件显示其内容里的逗号的个数

写一个MFC程序,选择了一个文本文件显示其内容里的逗号的个数

作者:undefined 时间:2019-11-06 11:43:22 0 删除 编辑
//获取文件路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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-16

  • 博文量
    124
  • 访问量
    678