Hi all,
I need to write a program that will first read a file and then
1. Output all the words that appear in a file.
2. Treat only sequences of letters and digits as words, i.e., all other characters such as punctuation marks should be used as word delimiters, but otherwise ignored.
Using the below code as a template..
#include <iostream>
#include<cdtg>
using namespace std;
void splitStringIntoWords(const string& line) {
int i = 0;
while (i < line.length()) {
if (isspace(line[i])) {
i = i + 1;
} else {
int j = i;
while ((i < line.length()) && (!isspace(line[i]))) {
i = i + 1;
}
string word = line.substr(j,i-j);
cout << word << endl;
}
}
}
int main()
{
string str = "";
cout << "Please input a string: ";
getline(cin,str);
cout << "----------" << endl;
splitStringIntoWords(str);
cout << "----------" << endl;
return 0;
}
I have no clue how to start off with.Can anyone please help me?I will really appreciate it.Thanks in advance.
Sana