fstream . Sorting data types from a txt file

can anyone give me the idea how can i sort out the data types from a text file. let suppose i have a txt file contain

----txt file---------

256 horse
-569 elements
1.256 GPA
32777 Cars
A Grade

-------end -----

i want to store integers in seprate variables of int type let suppose an int array. and stings in some char array. double in double type array and so on. i mean i want to sort the data from that file. please give me any help or ideas . i shall be thanks full to you all
i am new in C++ my knowledge about file stream as under
i know basics of opening txt file read and wrtie data from it. seekp() seekg() and tellp tellg fucntions. and all ios:: directives.
the above text file i showed was an example i want to clear the concept about sorting of any text file of any data. i want to store all data in their respective types.
i know to convert string into int and others like
int main()
    std::string test = "45";
    int myint = stoi(test);
    std::cout << myint << '\n';

but the problem in single line while using getline what should i do with whitespace and after while space any other words.
well, you can also call getline with three arguments:

getline(if_stream_name, string_name, ' ');

with that ' ' at the end as a delimiter, it will get stream input and assign it to that string up to the space ' '.. I think.

Last edited on
did't understand , you mean to initialize all type of arrays like int double char etc then read the file with delimiter, but how can reader sort the type into correct array? means if i read this line
256 cars
how can reader put 256 into int array and cars into char?
let me clear you that i don't know what the txt file have in it.
there might be this line
256 cars
or might be
cars 256
we don't know the orders of words which come first. i want to get an idea how the file-reader justify which type of word he is reading and in which data type he needs to store it
please idea
Topic archived. No new replies allowed.