Web Development

General discussion

Locked

C++ Forum

By Mark W. Kaelin Editor ·
Welcome to the C++ Forum. This is the place to post your C++ questions, share your best techniques, and express your opinion on topics that impact IT development.

We also encourage you to post your comments about the C++ TechMail.

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:

http://builder.com.com/techmails.jhtml?repID=u001

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Parse strings with stringstream

by Mark W. Kaelin Editor In reply to C++ Forum

Parse strings more easily with the to_stream function:

The March 3, C++ TechMail discusses parsing strings with stringstream. Have you used the to_stream function to parse strings? Tell us how it worked for you.

Collapse -

Handle stream errors with exceptions

by Mark W. Kaelin Editor In reply to C++ Forum

Implement exceptions to validate streams:

The March 5, C++ TechMail discusses handling stream errors with exceptions. How do you manage stream errors? Do you use member function exceptions?

Collapse -

failbit also triggers upon eof

by tehilinski In reply to Handle stream errors with ...

Not mentioned is that std::ios_base::failbit is also set upon encountering an end-of-file condition. This will trigger an exception if exceptions are enabled for failbit. In that case, you need to check for eof in the catch block (probably using ios::eof() ).

Collapse -

C++ TechMail question

by MaryWeilage Editor In reply to C++ Forum

The Mar. 10, 2003, C++ e-newsletter discusses resetting the stream state when encountering invalid data. What are your thoughts on this subject? Did you find the code examples in the newsletter helpful? Please let us know.

Collapse -

How will i handle a stream error?

by Volker.Goehrke In reply to C++ TechMail question

Hi,

your article about setting the stream state correctly when encountering invalid data was very interesting. I know now, how to handle an invalid state from the perspective of the operator implementation, but when i'm using the input operator, how can i display an error message, which points the user in the right direction? How should the caller of the operator deal with this situation?

I only played a little bit with input operators and it seemed more natural to me, to throw an exception with a detailed description of what was going on. My implementation of your example would be more like this:

template< class char_type, class char_traits>
std::basic_istream< char_type, char_traits> & operator >> (
std::basic_istream< char_type, char_traits> & streamIn, complex & value)
{
int nReal, nImag;

char_type ch;
streamIn >> ch;
if ( ch != '(')
throw ComplexBadFormatException("Missing opening bracket.");

streamIn >> nReal;
streamIn >> ch;
if ( ch != ',')
throw ComplexBadFormatException("Missing colon.");

streamIn >> nImag;
streamIn >> ch;
if ( ch != ')')
throw ComplexBadFormatException("Missing closing bracket.");

value.m_nReal = nReal;
value.m_nImag = nImag;

return streamIn;
}

greetings, Volker.

Collapse -

Return temporaries with proper code

by Mark W. Kaelin Editor In reply to C++ Forum

Return temporaries with proper coding techniques:

The March 12, C++ TechMail discusses the proper coding techniques for dealing with return temporaries. How do you handle return temporaries in your applications? Do you have a better technique? Tell us about it.

Collapse -

nice article, but....

by solrak29 In reply to Return temporaries with p ...

I found your atrictl very informative and good reminder in returning temporaries and example of temporary variable and the gotchas inbetween. I have to points though:

1. under djgpp there is no basic_stringstream...any ideas? I thought djgpp isthe same as gcc which uses the Silocone G STL...????

2. I would like to see a main for the "correct implementation"...??

3. Whats the difference between a stream and a stringstream??

Collapse -

actually forget #2

by solrak29 In reply to nice article, but....

After looking more at the code, I see you have the to_string implementation done....

nice article, but why doesn't the first implemenation work?

Collapse -

which article?

by John Torjo In reply to actually forget #2

Sorry, which article are talking about?

Best,
John

Collapse -

Get access functions with setter class

by Mark W. Kaelin Editor In reply to C++ Forum

Allow easier usage of your classes with the setter class:

The March 17, C++ TechMail discusses providing access or modifier functions, also known as getter and setter functions, when creating new classes. Have you used this technique in your applications? What class were you developing?

If you haven't subscribed to the C++ TechMail, there is no better time to take advantage of our free e-newsletter. Visit our e-newsletter subscription center to subscribe to this valuable TechMail today:
http://builder.com.com/techmails.jhtml?repID=u001

Related Discussions

Related Forums