myFile

#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_;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ycx旭

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值