Hey everybody,
I'm a little stuck on this simple program I'm trying to run. Right now it takes in a list of words and makes a single string out of them, but what I really want to do is make each word into its own new string, or maybe create an array of strings. The goal is to be able to find how how many copies of each word from the file there are, so I need to be able to compare each word with every other word individually.
How might I read each word into its own string?
#include<iostream>
#include<fstream>
using namespace std;
int main(int argc, char * argv[])
{
char buf[16];
ifstream fin;
if (argc < 2)
{
cout << "Usage: " << argv[0] << "<filename>\n";
return -1;
}
char * filename = argv[1];
cout << "File to open: " << filename << endl;
fin.open(filename);
if(fin.fail())
{
cout << "Failed to open file " << filename << endl;
return -1;
}
string str;
while (fin >> buf)
{
str.append(buf);
str.append(" ");
}
cout << str << endl;
fin.close();
return 0;
}
Thanks in advance!