64,639
社区成员
发帖
与我相关
我的任务
分享
#include <fstream>
#include <string>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
ifstream instream("C:\\Users\\pyx\\Desktop\\desktoop0327\\blog\\0-csdnQA\\3-txt\\test.txt");
string strin;
vector<string> vecstrin{};
if(instream){
while (getline (instream, strin)){//一行一行读取
cout << strin << endl;
vecstrin.push_back(strin);
}
}
else{
cout <<"Check the Path of File !" << endl;
}
if(!vecstrin.empty()){
string leftstr[vecstrin.size()];
string rightstr[vecstrin.size()];
for(int i = 0; i < vecstrin.size(); ++i){
bool bfound = false;
for(int j = 0; j < vecstrin[i].size(); ++j){
if(vecstrin[i][j] == ' '){
bfound = true;//处理前面空格部分
}
if(vecstrin[i][j] != ' ' && !bfound){
leftstr[i] = vecstrin[i].substr(0,j + 1);
}
if(vecstrin[i][j] == '='){//处理 '='右边的字符串
rightstr[i] = vecstrin[i].substr(j + 1,vecstrin[i].size() - j - 1);
}
}
}
for(int k = 0; k < vecstrin.size(); ++k) {//输出
cout <<leftstr[k]<<endl;
cout <<rightstr[k]<<endl;
}
}
return 0;
}