您的位置:首页 > 其它

数控技术发展趋势及产业化思考

2007-11-19 15:07 302 查看
ifstream 有一个getline() 函数 逐行读取
但是该函数不支持string类型
getline(char *p,int); 这样 必须 char[] 来做缓冲区,
学习Console程序时 , 用到过
string line;
cin >>line;
还有一种方法是
std::getline(cin,line);

那么在 ifstream 中也可以使用次方法
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main(int argc,char **argv){
ifstream out;
string str = "d:\\text.txt";
out.open(str.c_str(), ios::in);
string line;
while(!out.eof()){
std::getline(out,line);
cout <<line<<endl;
}
out.close();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: