Hi everyone,
I am trying to write a program which inputs words and then gives the count of how many times each word appeared at the input. The following code compiles, but gives
meassage when I try to run it.
Code:
#include <iostream>
#include<vector>
#include<string>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;
int main()
{
cout<<"Please input words followed by the end-of-file";
string x;
vector<string> word;
vector<int> word_count;
while (cin>>x)
{
bool a = false;
for (n=0; n!=word.size();++n)
if (x==word[n])
{
++word_count[n];
a=true;
}
if (a==false) word.push_back(x);
}
for (n=0; n!=word.size();++n)
cout<<word[n]<<"appeared "<<word_count[n]<<" times"<<endl;
return 0;
}
This is supposed to be fairly simple and I can think of couple of other ways of doing it but can't figure out why this particular code does not work.
BTW: How is GDB supposed to be used in the situation where I have to give program input?