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

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -