我的错误们(输入输出)
来源:互联网 发布:java gzip压缩目录 编辑:程序博客网 时间:2024/06/04 20:25
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main () {
ifstream inFile("test.txt");
int number;
string name = "";
/********************************/
inFile >> number; // inFile 会将换行符\n留在输入队列中
cout << number << endl;
/********************************/
while (name == "")
getline(inFile,name); // 读到换行符为止,并将换行符读取,所以换行符不存在在队列中,如果没有循环,则name输出为NULL
cout << name << endl;
inFile >> number; // 如果没有while(),则输入会跳过string类型的name,继续读整型将其保存在number中,因为number是整形,所以string被跳过
cout << number << endl;
return 0;
}
-bash-4.1$ more test.txt
5
tom
33
- 我的错误们(输入输出)
- 我对c++输入输出流的理解
- 标准输入输出与错误的缓冲
- 我的愚蠢错误
- 我的错误
- 我的常识性错误
- 我的错误(1)
- 我的错误1
- 我的错误笔记
- 我的错误
- 我的错误日志
- 我的惯性错误
- 我的常见错误
- 我的错误
- 关闭输入输出错误输出
- 我的Python学习之路之基本语法-输入输出
- 浅解C语言的标准输入输出、标准错误
- Node.js使用child_process运行脚本的输入输出错误
- my eclipse 优化
- SQL乐观锁与悲观锁
- javascript 指定网页跳转方式 两个提交按钮来提交到不同的页面
- 类型转换
- 1stuts2_redirctAction在struts.xml中的配置问题
- 我的错误们(输入输出)
- mysql数据库不能添加中文的解决办法
- 软件开发之质量保证
- CSDN阅读器(android版)开发总结
- 设计模式之一---工厂方法模式【Factory Method模式】
- 我的Android笔记(四)—— SQLite设置_id自增的方法
- checkstyle简单使用说明
- Java代码块的执行顺序
- 屏幕最左上角的 飞秋官方下载 字符