1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
void breakup(string, string&, string&, string&);
ifstream infile("Threewords.txt");
int main()
{
int pos;
string one, two, three, line;
while(getline(infile,line)){
cout<<"Original String: ";
breakup(line, one, two, three);
cout<<line<<endl;
cout<<one<<endl;
cout<<two<<endl;
cout<<three<<endl;
}
infile.close();
system("pause");
return 0;
}
void breakup (string line, string &one, string &two, string &three){
int pos, pos2, pos3;
pos=line.find(' ', 0);
one=line.substr(0,pos);
pos2=line.find(' ', pos+1);
two=line.substr(pos+1,pos2);
pos3=line.find(' ',pos2+1);
three=line.substr(pos2+1);
return;
}
|