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

文件的读入

撒旦 发布于 2007-06-07 20:13, 399 次点击

怎样将一个文件夹读入程序啊

3 回复
#2
aipb20072007-06-07 22:29
读文件夹?
文件吧?
#3
yuyunliuhen2007-06-07 23:25
read file ?
for example:
#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>
using namespace std;
int main()
{
fstream fin;
fin.open("d:\\filename.txt"); //the file path
if(fin.is_open()==false)
{
cerr<<"Can not open file,bye!\n";
exit(EXIT_FALLURE);

}
string item;
int count=0;
getline(fin,item,':');
while(fin){
count++;
cout<<count<<":"<<item<<endl;
getline(fin,item,':');
}
cout<<"done!"<<endl;
fin.close();



return 0;

}

#4
撒旦2007-06-08 13:57

谢谢

1