In: Computer Science
I need C++ program that Read an input file of text.txt one word at a time. The file should consist of about 500 words. The program should remove all punctuations,keep only words. Store the words in a built-in STL container, such as vector or map.Can someone help with any additional comments that I can understand the logic?thank you
program:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main(){
vector<string> v;
ifstream fin("test.txt");
string word;
while(fin>>word){
if(word.back()=='.'||word.back()==','||word.back()=='!'
||
word.back()=='?')
word.pop_back();
v.push_back(word);
}
for(string s: v)
cout<<s<<" ";
cout<<"\n";
}
sample test.txt file:
console output: