c++ 读取txt文件
来源:互联网 发布:留学机构 知乎 编辑:程序博客网 时间:2024/05/23 21:05
1,按行读取
// TEST_Read.cpp : 定义控制台应用程序的入口点。#include "stdafx.h"#include<iostream>#include<string>#include<fstream>//读取文件所需的文件头//以下为读取文件的一种方法:将文件每行内容存储到字符串中,再输出字符串using namespace std;int _tmain(int argc, _TCHAR* argv[]){ char buffer[10];fstream out;out.open("test.txt",ios::in);cout<<"test的内容如下:"<<endl;int i=0;while(!out.eof())//判断是否读到文件的末尾.{out.getline(buffer,10,'\n'); //表示该行字符达到10个或遇到换行就结束cout<<buffer<<endl;}out.close();cin.get();//读取最后一个enter键.return 0;}
// TEST_Read.cpp : 定义控制台应用程序的入口点。#include "stdafx.h"#include<iostream>#include<string>#include<fstream>//读取文件所需的文件头//直接读取txt文件中的数据,其中以txt中的空格符隔开using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int buffer[10];fstream out;out.open("test.txt",ios::in);cout<<"test的内容如下:"<<endl;for(int i=0;i<10;i++)out>>buffer[i];for(int i=0;i<10;i++)cout<<buffer[i]<<endl;out.close();}
0 0
- C#--读取txt文件
- C#Winform读取txt文件
- C#StreamReader 读取Txt文件
- C#winform读取.txt文件
- C格式化读取txt文件内容
- 第十五章,读取txt文件(C++)
- 【C#】读取和写入本地txt文件
- c++,对txt文件进行读取显示
- c语言一行一行的读取txt文件
- C/C++ | 17-1 读取文件.txt
- C读取txt教程
- C\C++读取txt
- C读取txt文档
- txt文件操作 读取
- TXT文件读取
- 读取TXT文件
- delphi 读取txt文件
- JavaScript读取Txt文件
- mysql 插入语句 删除语句
- 软件项目版本号的命名规则及格式
- Collections与Arrays的排序
- c#通过http协议连接php
- HOW TO: Find the Problem Exception Stack When You Receive an UnhandledExceptionFilter Call in the St
- c++ 读取txt文件
- UVA - 310 L--system(bfs+hash)
- 应用在tomcat上的部署以及将免安装的tomcat配置成服务自启动
- opencv中的绝对路径问题
- 指针数组 数组指针
- iOS开发 证书相关信息汇总
- Android KeyCode列表
- Aptana配置jQuery
- 自定义Android流布局实现推荐标签功能