为什么从文件流里读取字符时,空格和回车都没有了?

brxren 2003-10-19 05:26:40
如题!
include <iostream>
using namespace std;
#include <stdlib.h>
#include <fstream>

int main(int argc, char *argv[])
{
char gotChar;
int ch;
ifstream inStream("cifa.cpp");

if(!inStream)//inStream.fail();
{
cerr<<"Sorry!";
exit(1);
}
else
{
/**************开始程序的读取****************/


while((ch=inStream.peek())!=EOF)
{
inStream>>gotChar;
cout<<gotChar;

}
/********************************************/
}
return 0;
}
上面的程序为什么不能输出空格,空格到底能不能读到?
...全文
151 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
brxren 2003-10-19
  • 打赏
  • 举报
回复
谢谢!
ttlb 2003-10-19
  • 打赏
  • 举报
回复
string str;
// 读取一行
getline(inStream, str, '\n');
leyt 2003-10-19
  • 打赏
  • 举报
回复
得按行读才有空格 如getline()

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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