标准C++库中的 string 与 ifstream

caojunjie 2001-10-12 08:21:41
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool readParaFile(string filename){
ifstream parafile(filename);
return true;
}

ifstream 的构造函数 不识别 string 对象
都是标准库中的,又推荐用string不用char*,为什么?
望有大侠指点。
我的油箱:jjcao@comgi.com
jjcao@163.com
...全文
96 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
caojunjie 2001-10-13
  • 打赏
  • 举报
回复
#include <string>
#include <fstream>

string filename(a.txt);
ifstream parafile(filename.c_str());
string name;
getline(parafile,name,'\n');

我才查到,以上代码就解决了所有的问题。
招RD和QA 2001-10-12
  • 打赏
  • 举报
回复
这没什么奇怪的,IO stream早在90年代初就已经开发了,那时还没有string,当标准C++库统一后,现在的标准流库仍然沿用了经典流库的方式(在使用上几乎没有差异),才出现了你所说的问题。

69,371

社区成员

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

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