64,654
社区成员
发帖
与我相关
我的任务
分享
d:\>a
aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 11
22 33 44
bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 11 22
33 44 55
cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 11 22 33
44 55 66
dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 11 22 33 44
55 66 77
ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 11 22 33 44 55
66 77 88
d:\>
//在5楼看错了
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
vector< vector<string> > result;
string s;
fstream inf;
inf.open( "file.txt", ios::in);
while (getline(inf,s))
{
vector<string> vtemp;
if (s.length() >= 60)
for (int i = 0; i < 60; i+=2)
vtemp.push_back(s.substr(i, 2));
result.push_back(vtemp);
}
inf.close();
for (int i = 0; i < result.size();cout << endl, ++i)
for (int j = 0; j < result[i].size(); ++j)
cout << result[i][j] << " ";
return 0;
}
d:\>g++ test.cpp
d:\>a
aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 11
22 33 44
aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 11
22 33 44
aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 11
22 33 44
aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt uu vv ww xx yy zz 11
22 33 44
d:\>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
string s="AABBCCDDEEFF";
vector<string> v;
char ch;
string snull;
istringstream line(s);
int lcount=0;
while(line>>ch)
{
v.push_back(snull);
v[lcount]+=ch;
line>>ch;
v[lcount]+=ch;
++lcount;
}
for (int i=0;i<lcount;i++)
cout<<v[i]<<endl;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str="aabbccddeeff";
string str1[10];
for(int i=0;i<str.size()-2;i++)
{
str1[i]=str.substr(i,2); //保存到数组中
cout<<str1[i]<<endl;
}
return 1;
}
//仅以读一行为例
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
char result[30][2];
string s;
fstream inf;
inf.open( "file.txt", ios::in);
getline(inf,s);
memcpy(result, s.c_str(), 60);
inf.close();
for (int i = 0; i < 30;cout << endl, ++i)
for (int j = 0; j < 2; ++j)
cout << result[i][j];
return 0;
}