parsing/spliting data in C++ -
I send 6 data from the sensor with headers and tails along with (,) < Pre> I want to pars / sort this data and I can: Can someone help me to give this idea how to do this? I use Visual Studio C ++ 2010. My program is: is the value header and tail How to delete data, and how to create data in buffer This code shows how it can be done: Output: $ data0, data1, data2, data3, data4, data5%.
y0 = data0 y1 = data1 ... < / Pre>
#include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Sstream & gt; #include "stdafx.h" using namespace std; Int main () {string str = "$ data1, data2, data 3, data 4, data 5, data 6%"; String word; String Stream Stream (ARR); While (gateline (stream, word, ',')) cout & lt; & Lt; The word & lt; & Lt; "\ N"; }
$ data1 data2 data 3 data 4 data 5 data 6%
y1 = data 1 y2 = data2 ...
#include & lt; Iostream & gt; # Include & lt; Sstream & gt; #include & lt; String & gt; # Include & lt; Vector & gt; Int main () {std :: string s ("$ data0, data1, data2, data3, data4, data 5%"); S.erase (0, 1); // Remove header S.erase (s.size () - 1, 1); // Remove Tails // Pars Token std :: Vector & LT; Std :: string & gt; Token; // vector tokens will store std :: istringstream iss (s); (Std :: string token; std :: getline (iss, token, ',');) {tokens.push_back (token)); } // For output token (Constant & amp; T: token) {std :: cout & lt; & Lt; T & LT; & Lt; Std :: endl; }}
data0 data 1 data2 data3 data 4 data 5
Comments
Post a Comment