c++ - Splitting string in specific format which was created from int vector -


I have written a program that creates a comma-separated string outside the intersector's vector as follows: < pre> studs :: vector and lieutenant; Unsigned Integrated & gt; Vec; Vec.push_back (50); Vec.push_back (60); Vec.push_back (10); Vec.push_back (20); Vec.push_back (30); Vec.push_back (2); Vec.push_back (1); Std :: stringstream linemomstring; lineNumString.str (std :: string ()); LineNumString.clear (); std :: copy (Vec.begin (), Vec.end (), std :: ostream_iterator & lt; unsigned int> (linum string, ",")); std :: string string string (lineNumString.str ()); Line string = linestrings. substr (0, linestring.length () - 1); Std :: cout & lt; & Lt; Std :: endl & lt; & Lt; LineString;

If you see the output of the program above:

  `50,60,10,20,30,2,1`  < / pre> 

But I want to change my output in a slightly different format. I have to keep the maximum of three numbers on one line and the next line next. Like the below:

  50,60,10, 20,30,2, 1   

I used the child vector by Vec and tried to use them to create different strings, then I tried to divide the line lineString and then used those wires, please tell me that there is no better way to get the final output What is it? I am using VS2010, I can also use Boost features.

Thank you.

Classic loop path: #include & lt; Vector & gt; # Include & lt; Iostream & gt; # Include & lt; Sstream & gt; # Include & lt; Iterator & gt; Int main () {std :: vector & lt; Unsigned int & gt; Vec; Vec.push_back (50); Vec.push_back (60); Vec.push_back (10); Vec.push_back (20); Vec.push_back (30); Vec.push_back (2); Vec.push_back (1); For (auto it = VAC.bijene), this! = VAC.and ();) {std :: cout & lt; & Lt; * This ++; If (this! = VAC.and ()) std :: cout & lt; & Lt; ""; If ((- VAC.Bijin ())% 3 == 0) std :: cout & lt; & Lt; Std :: endl; } Return 0; }

Boost. Sarita Route:

  #include & lt; boost / config / warning_disable.hpp & gt; #include & lt; boost / spirit / include / karma.hpp & gt; # Include & lt; boost / spirit / include / phoenix_core.hpp & gt; # Include & lt; boost / spirit / include / phoenix_operator.hpp & gt; # Include & lt; Iostream & gt; #include & lt; Vector & gt; #include & lt; String & gt; Nameshot Karma = Promotion: Spirit :: Karma; Int main () {std :: vector & lt; Unsigned int & gt; V = {50, 60, 10, 20, 30, 2, 1}; Uses of Karma :: int_; Use of Karma: EOL; Use of Karma: Duplicate; Use of Karma: Generated; Std :: string out; Std :: back_insert_iterator & lt; Std :: string & gt; Out of it); Generated (this, int_   

duplicate : This duplicate attribute is int _ , which is mandatory, because predicate & amp; ; Consume it, to know whether we display the end of the line ( eol ) or not.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -