Sunday, 15 March 2015

c++ - File input and process data -



c++ - File input and process data -

i read text file , format of file is

method 1 method 2 insert 3 "james tan"

i using ifstream open text file , read items, when utilize >> read lines, causing name not read "james tan". attached below code , output.

ifstream fileinput; if(fileinput.is_open()){ while(fileinput.good()){ fileinput >>methondname>>value>>name; ......

output

methodname = method, method, insert value = 1, 2, 3 (must usigned integer) name = james

what improve way process reading of lines , contents. told getline. understand getline reads line rather single word single word.

next fstream fast?. cause, process 500000 lines of info , if ifstream not fast, other options have.

please advice on this.

method 1 method 2 insert 3 "james tan"

i take mean file consists of several lines. each line either begins word "method" or word "insert", in each case followed number. additionally, lines begin "insert" have multi-word name @ end.

is right? if so, try:

ifstream fileinput("input.txt"); std::string methodname; int value; while ( fileinput >> methodname >> value ) { std::string name; if(methodname == "insert") std::getline(fileinput, name); // whatever meant record. records.push_back(recordtype(methodname, value, name); // illustration }

c++ ifstream

No comments:

Post a Comment