I have a word pulled from a text file and put into an array. How do I then load that word into a separate array, so that I can count the number of letters in the word?
1 2 3 4 5 6 7
ifstream infile;
infile.open ("words.txt")
infile>>testword [1]>>testword [2];// I am guessing that testword [1] puts the whole word into the element 1.
cout<<testword [1];//displays whatever the first word in the text file was.
I now want to enter testword [1] into an array so that each letter is an element....any ideas how to do this?
do you really need the struct? It's pretty trivial to write:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// in main
string input1, input2
vector<string> firstWord;
// open file
while(/* file is good */)
{
fin >> input1 >> input2;
firstWord.push_back(input1);
}
// later just display the vector
for( int i = 0; i < firstWord.size(); ++i )
{
cout << firstWord[i] << endl;
}