注册 登录
编程论坛 C++教室

[讨论]改一下程序,关于

ezinma1210 发布于 2007-07-02 18:23, 635 次点击

有一些日期,在文件中,后面加*号的表示要加班的日期,试汇总所有每个月25号的天数,如果是加班日,则该天乘2.
有一些日期,在文件abc.txt中,后面加*号的表示要加班的日期,试汇总所有每个月25号的天数,如果是加班日,则该天乘2.
Oct.25 2003
Oct.26 2003
Sep.12 2003*
Juy.25 2002*
App.25 2004


#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{ int sum=0;
ifstream in ("F:\abc.txt");
string s;
while(getline(in,s))
{
if(s.find("25")!=string::npos)
{
if(s.find('*')!=string::npos)
sum+=2;
else
sum++;
}
}
cout<<"sum="<<sum<<endl;
system("pause");
}
1 回复
#2
kisscjy2007-07-02 19:13
你所打开的文件路径错了~~

正确的写法是这样:

ifstream in ("F:\\abc.txt");

这样就可以了~~
1