Inputting multiple variable types from file

Hi All,

This might seem like a silly question, but I'm still quite a newbie in regards to c++, but I was wondering how i might input a file whose lines contain multiple data types, each variable is then manipulated in a specific way then formatted output. I know how to output the data, but really not sure how to get the input. The structure I'm looking for is something like this:

Each line of the file input looks like this:

TEXT1 TEXT2 float1 float2 float3 integer1
.
.
.

and would like each TEXT to be inputted to its own variable, the same going for the floats and integers.

from (i = beginning to i = endoffile){

inputline >> a=TEXT1 >> b=TEXT2 >> c =float1 >> d = float2 >> e = float3 >> f = integer1

PROCEDURE TO MANIPULATE DATA

cout >> a >> setw(5) >> b >> setw(5) >> c >> setw(10) >> d >> setw(10) >> e >> setw(10) >> f >> setw(15)

}

I'm lost and feel a little foolish for asking lol

Thanks for any help you can give!
well ... i don't really understand what you want but ...
let's say we have

1
2
3
4
5
6
7
8
9
10
11
12
string s1, s2 ;
float f1, f2, f3 ;
int i1 ;

while (!file.EOF())
{
FILE >> s1 >> s2 >> f1 >> f2 >> f3 >> i3 ;

function (s1) ; function (s2) ;
function (f1) ; function (f2) ; function (f3) ;
function (i3) ;
}


so you can use the same name of a function and change the type of the argument and it will be called correctly for each argument :) like :

function add (int a, int b) ; would add the integers
function add (matrix a, matrix b) ; would add the matrixes

you will still have to define each of them , but it helps at keeping a cleaner code since both functions have same purpose . this is called overloading a function :)
NEVERMIND THE LAST MESSAGE.

Got it working, thank you loads!!!
Last edited on
Topic archived. No new replies allowed.