Reading from a file with delimiters and saving into an object c++ -
i'm writing program beginner c++ class read strings file , store them object in vector. file uses ',' delimiter , have whitespaces within strings. have working using bunch of getlines, wondering if there way clean code or possibly optimize it.
while getline(ifs,s){ string stream ss(s); getline(ss,str1,','); getline(ss,str2,','); getline(ss,str3,','); //i take these variables , pushback onto vector using object's //constructor }
i have that, wondering if theres better way it. been looking overloading extraction operators, think run issue of not being able overload whitespace delimiter >>
generally, use tokenizer this. boost.tokenizer great, beginner c++ class, you'll want go strtok() http://en.cppreference.com/w/cpp/string/byte/strtok
tokenize input data using strtok() , loop on tokens.
Comments
Post a Comment