Reading file seperated by white spaces into dynamic array C++ -


hi read file , put numbers seperated white space int different array. example file read

15 10 2 20 1 30 1 

this did

    while(!file.eof()){          file>>first[count++];      } 

by doing taking line line want read until white space , put number after whitespace different array. result array (assume first , second dynamic integer arrays)

first={15,10,20,30} second ={0,2,1,1} 

you should use string streams.

#include <sstream> ...  string line; while(getline(file, line)) {    istringstream iss(line);    int firstnumonline, secondnumonline.    iss >> firstnumonline;    first.push_back(firstnumonline);    if(iss >> secondnumonline)    {         //...          second.push_back(secondnumonline)    }    else    {        //... there no second number on line.        second.push_back(0);    } } 

here, first , second assumed vectors


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -