I have to read a few words from a file and save it into a tree so i can search. the file contains these words.
cat
dog
car
mother
nike
hat
last
this is what i have so far
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
long int i=0;
char ch;
char out[100];
ifstream iFile("c:/dictionary.txt"
;
if (! iFile)
{
cout << "Error opening input file" << endl;
exit(1);
}
while(iFile.get(ch))
{
switch (ch) {
case ' ':
i=i+5;
break;
case '\n':
i=i+5;
break;
break;
default:
out=ch;
cout<<out<<i;
i++;
break;
}
}
}
i want to know how i can read and store each word in a seperate string so i can later load these strings into a tree
cat
dog
car
mother
nike
hat
last
this is what i have so far
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main()
{
long int i=0;
char ch;
char out[100];
ifstream iFile("c:/dictionary.txt"
if (! iFile)
{
cout << "Error opening input file" << endl;
exit(1);
}
while(iFile.get(ch))
{
switch (ch) {
case ' ':
i=i+5;
break;
case '\n':
i=i+5;
break;
break;
default:
out=ch;
cout<<out<<i;
i++;
break;
}
}
}
i want to know how i can read and store each word in a seperate string so i can later load these strings into a tree