Reading from text file

I want to write a Program that opens a txt file called "text.txt" In the File there will be a word or a word, a space, and a number and then an enter. For Example:
text.txt:

bla 2
banana
sldjfkalj 4
hohoho 2
ji
ja

Then the program declares 2 vectors one for strings and one for ints. If a word in the text file does not have a number after it it stores a one. Let me show u what I mean. When running with this example the vectors will look like this:
strings: {"bla","banana","sldjfkalj","hohoho", "ji, "ja"}
ints: {2,1,4,2,1,1}

Why I found it difficult: In my program when it decides if it should read 2 or 1 value it already skips that line when deciding before it can actually read.

Thanks in advance and sorry for the horrible English (im from switzerland:))
If anyone would like me to try to explain more, no problem.

EDIT: The reason I didnt show my code is because there were alot of ways I tried out but the were all different. The basic Idea is:
int main(){
vector<int> ints;
vector<string> strings;
fstream FileReader;
FileReader.open("text.txt");
while(FileReader is still okay){
//Decide whether to read just once or twice
//read that many times
//push back strings
//push back ints with one or another value
}
return 0;
}
Last edited on
It would help, if you would show your code.
Topic archived. No new replies allowed.