Greetings everyone...
I'm new to Standard Template Libraries thus I'm encountering problems now and then...
I managed to get some examples on integer lists to work but the string lists give me nothing but grief...
What I'm trying to do is to read a series of words from an input text file, insert them into a list and then print them on the screen. However, the following code only prints the last word repeatedly, the number of times equal to the words in the file, which leads me to believe I actually succeed in creating the list but can't read properly from it.
The code is as follows... And help would be appreciated.
Thanks in advance...
Barış
#include <list>
#include <iostream>
using namespace std ;
#include <stdio.h>
#include <stdlib.h>
void main (void)
{
FILE *inputFile = fopen("input.txt", "r");
if(inputFile == NULL)
{
std::cout << "Dosya acilamadi...";
}
list<char *> wordList;
char currentword[100] = "";
while(!feof(inputFile))
{
fscanf(inputFile, "%s", currentword);
wordList.push_back(currentword);
printf("%s\n", currentword);
}
list<char *>::iterator wordListIterator = wordList.begin();
for(list<char *>::iterator ai=wordList.begin(); ai!=wordList.end(); ++ai)
{
std::cout << *ai << " ";
}
fclose(inputFile);
}
The input file is as follows :
Deneme Anne Elvis Abba
Lives cat Baba internet
Kazak Baba