c++ - How to split a full=number into two groups according to their position(even or odd) -


i need split txt file 2 arrays txt file contains full number.can without string? example,for input

4(how many line) 2 1 3 7 8 0 3 7 

i want array 1 contains (firt number in line)

{2  3  8  3} 

array 2 contains (second number in line)

{1   7  0   7} 

how can that?just curious...here code not work..

ifstream ifs("sth.txt"); int g; ifs>>g; int girl[g]; int boy[g]; for(int i=0;i<2*g,i++;){ if (i%2==0)ifs>>gil[g]; if (i%2==1)ifs>>boy[g];} cout<<boy[1]; 

ifstream ifs("sth.txt"); int g; ifs>>g; int girl[g]; int boy[g]; for(int i=0;i<g,i++;){     ifs>>girl[i];     ifs>>boy[i]; } cout<<boy[0]; 

you reading girl[g] , boy[g] instead of 0..(g-1).

i changed reading: 2 ints insted of 1 in 1 iteration of loop.

at end changed counting first (index 0) instead of second element of boy.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -