C++ 读写txt文件
来源:互联网 发布:飞鸽网络打印如何使用 编辑:程序博客网 时间:2024/06/05 22:51
#include <iostream>#include <fstream>#include <string>#include <stdio.h>#include <vector>#include <iomanip>using namespace std;//字符串分割函数std::vector<std::string> split(std::string str,std::string pattern){std::string::size_type pos;std::vector<std::string> result;str+=pattern;//扩展字符串以方便操作int size=str.size();for(int i=0; i<size; i++){pos=str.find(pattern,i);if(pos<size){std::string s=str.substr(i,pos-i);result.push_back(s);i=pos+pattern.size()-1;}}return result;}int main(){ifstream infile;string filename = "s1.txt";char buffer[200];infile.open(filename);if(!infile){cout<<"打开文件错误"<<endl;return -1;}while(!infile.eof()){infile.getline(buffer,200);string s(buffer);std::vector<std::string> sets = split(s," ");for(int i=0; i<sets.size(); i++){std::cout<<setw(16)<<sets[i];}cout<<endl;}infile.close();system("pause");return 0;}
0 0
- 【c#】读写txt文件
- C语言读写txt文件
- C语言读写txt文件
- c读写txt文件示例
- C-语言TXT文件的读写
- 【C#】txt的读写
- VB读写TXT文件
- txt文件读写
- C#读写txt文件
- Java读写txt文件
- txt文件读写
- .Txt 文件读写
- DataGrid读写txt文件
- javascript 读写txt文件
- javascript 读写txt文件
- java读写txt文件
- js读写txt文件
- vs2010读写txt文件
- 异步任务
- C++实验四【项目1:利用循环求和】求1000以内所有偶数的和
- 解决Debug JDK source 无法查看局部变量的问题方案
- EventBus使用详解(一)——初步使用EventBus
- Image warping / distortion
- C++ 读写txt文件
- Android Studio和Eclipse使用不同对比
- 多线程基础题目
- apache config httpd.conf file防止目录列表被浏览、敏感目录或文件限制IP访问
- 更改log4j的默认配置文件路径
- 未名湖旁的博雅塔
- Android 属性动画(Property Animation) 完全解析 (上)
- 串口DCB结构详解
- 常见条码的解释