473,396 Members | 2,038 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,396 software developers and data experts.

Eating whitespace but not eol

Is there a reasonable way (apart from parsing the line myself which I
can do, but would like to avoid) to have an extract fron cin return a
null string when a (second) line ender is entered, but also to ignore
other whitespace characters before starting the extract?

The situation I have is that I would like to present a default value
and have the user accept it by simply pressing the retrun key, but to
enter the proper value, if the default is unacceptable.

Oct 1 '07 #1
4 3536
Michael Angelo Ravera wrote:
Is there a reasonable way (apart from parsing the line myself which I
can do, but would like to avoid) to have an extract fron cin return a
null string when a (second) line ender is entered, but also to ignore
other whitespace characters before starting the extract?
Are you aware of 'getline' function? How about 'ignore' member of
'istream' (or whichever it is, actually)?
The situation I have is that I would like to present a default value
and have the user accept it by simply pressing the retrun key, but to
enter the proper value, if the default is unacceptable.
If you use getline, you don't have to parse anything yourself, you
could still form 'istringstream' from the string and extract from it
just like you would from your input stream.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 1 '07 #2
On 2007-10-01 20:34, Michael Angelo Ravera wrote:
Is there a reasonable way (apart from parsing the line myself which I
can do, but would like to avoid) to have an extract fron cin return a
null string when a (second) line ender is entered, but also to ignore
other whitespace characters before starting the extract?

The situation I have is that I would like to present a default value
and have the user accept it by simply pressing the retrun key, but to
enter the proper value, if the default is unacceptable.
Perhaps std::getline() is what you want.

--
Erik Wikström
Oct 1 '07 #3
On Oct 1, 12:12 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Michael Angelo Ravera wrote:
Is there a reasonable way (apart from parsing the line myself which I
can do, but would like to avoid) to have an extract fron cin return a
null string when a (second) line ender is entered, but also to ignore
other whitespace characters before starting the extract?

Are you aware of 'getline' function? How about 'ignore' member of
'istream' (or whichever it is, actually)?
The situation I have is that I would like to present a default value
and have the user accept it by simply pressing the retrun key, but to
enter the proper value, if the default is unacceptable.

If you use getline, you don't have to parse anything yourself, you
could still form 'istringstream' from the string and extract from it
just like you would from your input stream.
I am very aware of getline. This basically amounts to parsing the line
myself. What I want to do here is to have the previous extract
operation remove any trailing whitespace and one set of line enders,
if any, but to have the current operation return a null string on
encountering line ender, but to ignore any leading whitespace. I can
certainly code it this way, but there should be any easier way and I
suspect that there is.

Oct 1 '07 #4
On 2007-10-01 10:27:37 -1000, Michael Angelo Ravera
<ma******@prodigy.netsaid:
>
I am very aware of getline. This basically amounts to parsing the line
myself.
Not inherently:

std::string str;
while (getline(cin, str))
{
std::istrstream line(str);
line >whatever >somethingelse >morestuff;
}

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 1 '07 #5

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

Similar topics

2
by: Wolfgang Jeltsch | last post by:
Hello, it is often convenient to insert whitespace into an XML document in order to format it nicely. For example, take this snippet of a notional DocBook XML document: <para> This is a...
2
by: Carlitos | last post by:
Hi there, A class in Xerces J-API (Java) called TextImpl contains a property that returns whether the text is ignorable whitespace...
2
by: Carlitos | last post by:
Hi there, A class in Xerces J-API (Java) called TextImpl contains a property that returns whether the text is ignorable whitespace...
0
by: Shan Plourde | last post by:
Hi everyone, I have been using various regular expressions with the ASP.NET RegularExpressionValidator for quite some time. In general it works very well. One of the common regex's that I use...
3
by: David Pratt | last post by:
Hi. I am splitting a string on a non whitespace character. One or more whitespace characters can be returned as items in the list. I do not want the items in the list that are only whitespace (can...
56
by: infidel | last post by:
Where are they-who-hate-us-for-our-whitespace? Are "they" really that stupid/petty? Are "they" really out there at all? "They" almost sound like a mythical caste of tasteless heathens that "we"...
9
by: amattie | last post by:
Does anyone have any idea on how I can strip the extra whitespace in the XML that shows up when I receive a response from an ASP.NET 2.0 webservice? This has been discussed before, but no one has...
5
by: John Gordon | last post by:
My XSLT files have many occurrences of this general pattern: <a> <xsl:attribute name="href"> <xsl:value-of select="xyz" /> </xsl:attribute> </a> When I execute an XSL transform, the...
13
by: Chaim Krause | last post by:
I am unable to figure out why the first two statements work as I expect them to and the next two do not. Namely, the first two spit the sentence into its component words, while the latter two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.