Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Boost Tokenizer Question

Status
Not open for further replies.

SmileeTiger

Programmer
Mar 13, 2000
200
US
I have a file that has it's fields seperated by ^A characters (0x01) and want to use the boost tokenizer to split the fields.

However, when I attempt to use 0x01 directly as the token I get a complaint about type mismatches. To get around that issue I created a char array to hold the token but man is it hacky:
//start of fugly code
char cSep[1];
str[0] = char(0x01);
//Tokenize the fields
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(cSep);
tokenizer tokens(strDataLine, sep);
//End of fugly code

for(tokenizer::iterator itField = tokens.begin(); itField != tokens.end(); ++itField)
{
//Random field processing code here
}

Can anyone suggest a different way of setting the seperator in a less fugly way? That char array has got to go :(
 
I pasted the wrong version of my code (wht a typo). The correct code should be :
//start of fugly code
char cSep[1];
cSep[0] = char(0x01);
//Tokenize the fields
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(cSep);
tokenizer tokens(strDataLine, sep);
//End of fugly code

for(tokenizer::iterator itField = tokens.begin(); itField != tokens.end(); ++itField)
{
//Random field processing code here
}
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top