473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Finding the first non-white space character using sscanf (C++ equivalent)


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<stringtype)

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?

Oct 10 '06 #1
1 3278

On Oct 10, 11:42 am, "Dilip" <rdil...@lycos.comwrote:
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?
Found it myself.

string ess(encodedsymbol);
istringstream iss(ess);
string first, second, third;

iss >first >second >third;

Oct 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
4
by: Robb Meade | last post by:
Hi all, Ok, lets say I have the following, Request.Form collection which produces this (as the element names) a b c d
11
by: Solomon Grundy | last post by:
Select trunc(sysdate,'MM') from dual of course gives me the first day of the month, may I ask what the query is to find the first saturday of the month?
1
by: Richard C Buchanan | last post by:
I have a table as follows: - user_id (key) - user_email_address (text) - user_request_date (text) - user_sent_date (time/date) An automated macro...
2
by: Fraser Ross | last post by:
I want to use std::find_if to find the first char of a sequence that is not a digit. Can this be done the STL components alone? I can use a predicate functor written myself like this: struct...
4
by: Merlin | last post by:
Hi there, I would like to check if a string is a valid zip code via Javascript. Length and existents are already checked. How can I find out if the string contains characters other than...
0
by: iphinitiy2006 | last post by:
i have a workbook right now that has two sheets. One sheet acts as a calculator and the other sheet is a log of all the calculations that are performed. I am trying to write code that will copy a...
3
by: Rizvi | last post by:
The Grammer is given: S ---> id=E; E ---> E+T | E-T | T T ---> T*F | T/F | F F ---> P^F | P P ---> -P | L L ---> (E) | id | num -------------------------------- I've fond the following...
23
by: andersond | last post by:
I have a form with 31 questions each of which could cause an application to be rejected. I have 10 fields named issue 1...issue10. If a problem is found I want to save a message to the first empty...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.