fstream 输入的基本用法(供个人备忘)
2012-05-27 14:45
253 查看
简述:从map.txt读取一幅地图信息,然后输出
内容:
1)fstream读取文件
2)getline(fin,strLine)读取文件,并且赋值给字符数组保存
map.txt
输出:
内容:
1)fstream读取文件
2)getline(fin,strLine)读取文件,并且赋值给字符数组保存
#include <fstream> #include <iostream> #include <string> using namespace std; int main(int argc, char **argv) { ifstream fin("map.txt"); int width = 21; int height = 19; char *mapInfo = new char[width * height]; int cntLine = 0; while(!fin.eof()){ string line; getline(fin,line); for(int j = 0;j < width;j++) mapInfo[cntLine * width + j] = line[j]; cntLine++; } cout << "MapInfo : " << endl; for(int i = 0;i < height;i++){ for(int j = 0;j <width;j++){ cout << mapInfo[i * width + j]; } cout << endl; } fin.close(); return 0; }
map.txt
111111111111111111111 100000000000000101001 1000010g0000101000001 100000000000000000001 1000000000000000000s1 100010000000000000001 1000000g0001000s00001 100000100001000000001 1000000g0001000100001 100000000000010000011 100000100000000000001 100000000000000000011 100100100000100000001 100000000000000000001 100010000000000000001 100000000000000011001 100000100010000000001 101000000100000010001 111111111111111111111
输出:
相关文章推荐
- c++文件流基本用法(fstream, ifstream, ostream)
- c++文件流基本用法(fstream, ifstream, ostream)
- map 基本用法 (输入字符串与数值,统计输入字符串次数及该数据的平均值)
- C语言中基本的输入和输出函数的用法第一讲(C语言学习随笔三)
- c++文件流基本用法(fstream, ifstream, ostream)
- c++文件流基本用法(fstream, ifstream, ostream)
- c++文件流基本用法(fstream, ifstream, ostream)
- fstream和ifstream详细用法,c++文件输入输出要注意!!
- 个人整理git的基本用法
- JAVA基础 day21 字节流的输入和输出 字节流的缓冲区 (自己实现BufferedInputStream) 键盘输入 转换流的用法 改变标准输入输出设备 IO流操作的基本规律
- 【基础备忘】set--常见成员函数及基本用法
- c++文件流基本用法(fstream, ifstream, ostream)
- Android中Activity的基本用法(备忘)
- c++文件流基本用法(fstream, ifstream, ostream)
- c++文件流基本用法(fstream, ifstream, ostream)
- c++文件流基本用法(fstream, ifstream, ostream)
- bootstrap-分裂式菜单(向上、向下),输入框组, form基本用法
- c++文件流基本用法(fstream, ifstream, ostream)
- Android中BroadcastReceiver的基本用法(备忘)
- Python2.7 -- 基本用法备忘