Write a program to process string data The input is on one l
Solution
solution
#include<stdio.h>
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main () {
string sentence;
ifstream myfile (\"D:\\\\example.txt\");
if (myfile.is_open())
{
while ( getline (myfile,sentence) )
{
cout<<\"the sentence with delimeters\"<<endl;
cout << sentence << \'\ \';
std::string str =sentence;
std::string delim = \":\";
size_t position = 0;
std::string token;
while ((position = str.find(delim)) != std::string::npos) {
token = str.substr(0, position);
std::cout << token << std::endl;
str.erase(0, position + delim.length());
}
std::cout << str << std::endl;
}
myfile.close();
}
else cout << \"Unable to open file\";
return 0;
}
output
the sentence with delimeters
george:william:john:abraham
george
william
john
abraham
the sentence with delimeters
kate:winslin
kate
winslin
the sentence with delimeters
hello there how: r u iam fine:
hello there how
r u iam fine

