vector<string> wordstocheck; in.open("readin.txt"); string line; string word = ""; int linecount = 0; while (getline(in, line)) { //cout << line << endl; for (int i = 0; i < line.size(); i++) { if(isalpha(line[i])) { word.push_back(tolower(line[i])); } else if (line[i] == ' ' || ispunct(line[i]) || line[i] == '\n') { wordstocheck.push_back(word); word = ""; } } linecount++; } for (int i = 0; i < wordstocheck.size(); i++) { cout << wordstocheck[i] << endl; } system("pause"); } The code above reads in the following from a .txt file:
If debugging is the process of removing bugs. Then programming must be the process of putting them in. I'm trying to get the program to recognize each word, and save that individual word into a vector, and then print that vector of words out. It does pretty well with the exception of the two 'the's on the first and third lines.
Output: if debugging is theprocess of removing bugs then programming must be theprocess of putting them in Press any key to continue . . . It doesn't split up "theprocess" as I had hoped.