D
Dilip
I have piece of code that breaks apart a string filled with spaces into
distinct strings each containing the apporpriate non-whitespace
characters using sscanf
char encodedsymbol[] = "IBM RRR XO";
char first[20], second[20], third[20];
sscanf(encodedsymbol, "%s%s%s", first, second, third);
Is there a C++ way to do this?
I had a little templated code that tokenizes a string based on a
delimiting character like this:
template<typename Str, typename Separator, typename Container>
void str_tokenize(const Str& str, const Separator delim, Container&
cont)
{
std::stringstream stream(str);
Container::value_type token;
while (!std::getline(stream, token, delim).fail())
cont.insert(cont.end(), token);
}
(where Container is almost always a vector<string> type)
I know I can modify this slightly to account for spaces... but I was
just wondering if there was a more straightforward C++ way to do it?
distinct strings each containing the apporpriate non-whitespace
characters using sscanf
char encodedsymbol[] = "IBM RRR XO";
char first[20], second[20], third[20];
sscanf(encodedsymbol, "%s%s%s", first, second, third);
Is there a C++ way to do this?
I had a little templated code that tokenizes a string based on a
delimiting character like this:
template<typename Str, typename Separator, typename Container>
void str_tokenize(const Str& str, const Separator delim, Container&
cont)
{
std::stringstream stream(str);
Container::value_type token;
while (!std::getline(stream, token, delim).fail())
cont.insert(cont.end(), token);
}
(where Container is almost always a vector<string> type)
I know I can modify this slightly to account for spaces... but I was
just wondering if there was a more straightforward C++ way to do it?