简单+不会

csdn5211 2003-08-19 01:48:41
正在看《Thingking in c++》,一道很简单的题,“打开一个文件,统计空格的个数”,统计空格个数我会,可是什么文件怎么办呐?请给源码。
...全文
71 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
yakai 2003-08-20
  • 打赏
  • 举报
回复
这是你自己应该告诉程序的,一般放在当前目录下就可以了
csdn5211 2003-08-20
  • 打赏
  • 举报
回复
可是程序怎么知道文件在哪啊?
bm1408 2003-08-20
  • 打赏
  • 举报
回复
#include <fstream.h>

ifstream soucefile ( "from.txt" , ios::out | ios::nocreate );
if ( soucefile.fail() )
{
cout<<"cannot open the soucefile."<<endl;
}
ofstream destinfile ("output.txt" , ios::in );
if ( destinfile.fail() )
{
cout<<"cannot create the destinfile."<<endl;
}
happycock 2003-08-20
  • 打赏
  • 举报
回复
DOS下怎么访问不在当前目录的文件?一样的吗。
文件的完整名称是这样的,路径+文件名
比如d:\my\xx.txt
csdn5211 2003-08-20
  • 打赏
  • 举报
回复
假如不是当前目录呢?
happycock 2003-08-19
  • 打赏
  • 举报
回复
#include <fstream>
using namespace std;
int main()
{
ifstream a("filename");
}
a就是文件对象了,其他的对象怎么用,仿照就行了。
jack_wq 2003-08-19
  • 打赏
  • 举报
回复
#include <stdio.h>

main()
{
int c,i,nwhite,nother;
int ndigit[10];
nwhite=nother=0;
for(i=0;i<10;i++)
ndigit[i]=0;
while((c=getchar())!='\EOF')
if(c>='0'&&c<='9')
++ndigit[c-'0'];
else if(c==' '||c=='\n'||c=='\t')
++nwhite;
else
++nother;
printf("digit=");
for(i=0;i<10;i++)
printf("%d",ndigit[i]);
printf(",white space=%d,other=%d\n",nwhite,nother);
}
vsfan 2003-08-19
  • 打赏
  • 举报
回复
use fstream()
look it up in msdn
ppm07 2003-08-19
  • 打赏
  • 举报
回复
#include <fstream.h>

ifstream soucefile ( "from.txt" , ios::out | ios::nocreate );
if ( soucefile.fail() )
{
cout<<"cannot open the soucefile."<<endl;
}
ofstream destinfile ("output.txt" , ios::in );
if ( destinfile.fail() )
{
cout<<"cannot create the destinfile."<<endl;
}
jack_wq 2003-08-19
  • 打赏
  • 举报
回复
<C程序设计语言〉第二版(英文版)22页!

69,364

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧