myFile
2016-03-23 17:37
281 查看
#include <iostream>
#include <fstream> // c++ 文件IO头
#include <string>
#include<vector>
#include <string>
using namespace std;
#include "test.h"
int main(){
string strPath = "c:/Users/sjyt/Desktop/bpc";
string strTxtName = "/config.txt";
string str = strPath + strTxtName;
const char* path = str.c_str(); // 你要创建文件的路径
ofstream fout(path);
if (fout) { // 如果创建成功
fout << "写入内容\nhehehehehe" << endl; // 使用与cout同样的方式进行写入
fout.close(); // 执行完操作后关闭文件句柄
}
ifstream in(path);
string s;
while (getline(in, s))//着行读取数据并存于s中,直至数据全部读取
cout << s.c_str() << endl;
string str2 = ",1,2,3,,,";
test* tet = new test();
vector<string> vecS = tet->split(str2,",");
vecS.size();
delete tet;
return 0;
}
vector<string> test::split(const string& str, string sep )
{
vector<string> ret_;
if (str.empty())
{
return ret_;
}
string tmp;
string::size_type pos_begin = str.find_first_not_of(sep);
string::size_type comma_pos = 0;
while (pos_begin != string::npos)
{
comma_pos = str.find(sep, pos_begin);
if (comma_pos != string::npos)
{
tmp = str.substr(pos_begin, comma_pos - pos_begin);
pos_begin = comma_pos + sep.length();
}
else
{
tmp = str.substr(pos_begin);
pos_begin = comma_pos;
}
if (!tmp.empty())
{
ret_.push_back(tmp);
tmp.clear();
}
}
return ret_;
}
#include <fstream> // c++ 文件IO头
#include <string>
#include<vector>
#include <string>
using namespace std;
#include "test.h"
int main(){
string strPath = "c:/Users/sjyt/Desktop/bpc";
string strTxtName = "/config.txt";
string str = strPath + strTxtName;
const char* path = str.c_str(); // 你要创建文件的路径
ofstream fout(path);
if (fout) { // 如果创建成功
fout << "写入内容\nhehehehehe" << endl; // 使用与cout同样的方式进行写入
fout.close(); // 执行完操作后关闭文件句柄
}
ifstream in(path);
string s;
while (getline(in, s))//着行读取数据并存于s中,直至数据全部读取
cout << s.c_str() << endl;
string str2 = ",1,2,3,,,";
test* tet = new test();
vector<string> vecS = tet->split(str2,",");
vecS.size();
delete tet;
return 0;
}
vector<string> test::split(const string& str, string sep )
{
vector<string> ret_;
if (str.empty())
{
return ret_;
}
string tmp;
string::size_type pos_begin = str.find_first_not_of(sep);
string::size_type comma_pos = 0;
while (pos_begin != string::npos)
{
comma_pos = str.find(sep, pos_begin);
if (comma_pos != string::npos)
{
tmp = str.substr(pos_begin, comma_pos - pos_begin);
pos_begin = comma_pos + sep.length();
}
else
{
tmp = str.substr(pos_begin);
pos_begin = comma_pos;
}
if (!tmp.empty())
{
ret_.push_back(tmp);
tmp.clear();
}
}
return ret_;
}
相关文章推荐
- js 模块化开发
- 仿小米增加短信的收藏功能
- 断言(了解即可)
- 英文版的VC6.0,在 “Find in Files”中查找了中文引起崩溃
- Linux资源控制(LXC控制CPU,内存)
- 对于java的一些想法!
- java IO复习(三)
- Google官方BottomNavigationBar底部导航的使用
- Server 2012 网卡teaming 和 cisco 交换机配置, network card teaming
- 关于ListView加载优化的一些领悟
- c++继承与组合
- Lucidpress | Free Design Tool(Web打印)
- select标签使用
- solr 原子更新
- android binder进程间通信
- Caffe配置---配置Windows版 Caffe
- linux部署计划任务
- C# 在excel中查找及替换数据
- tomcat 8.0 SQLSERVER 数据库连接池的创建方法
- JS数组复制(克隆)