Author |
Message |
Don #1 / 12
|
 String Stream Formatting
This is my first foray into the world of streams and formatting, so maybe I just do not get the fundamentals. However, I am at a loss on where to go to figure this out. In my header I include the string stream class: #include <strstrea.h> In the code, I create the string and use it: ostrstream ostr(ControlString,25); ostr.seekp(0); ostr.width(8); ostr.fill(0); ostr << showbase(hex); ostr << ACUMessage.MessageStart; ostr << ends; SetDlgItemText(IDC_Preamble_Rx, ControlString ); but get the error: error C2065: 'showbase' : undeclared identifier for showbase. The way I understand it, ostrstream is derived from ios_base. I have even tried prefixing it with ios_bass:: with no luck. Would someone be so kind as to enlighten me on where I am screwing up or at maybe provide a good reference on the topic?! Thanks!! Don
|
Sun, 27 Feb 2005 21:23:43 GMT |
|
 |
Craig Power #2 / 12
|
 String Stream Formatting
Quote:
> This is my first foray into the world of streams and formatting, so maybe I > just do not get the fundamentals. However, I am at a loss on where to go to > figure this out. > In my header I include the string stream class: > #include <strstrea.h>
I would strongly recommend using <sstream> (which, incidentally, will put everything in the standard namespace). strstreams are deprecated and should be avoided absent a specific need. And if you still want to use strstreams, you should use <strstream>, not the .h version. Quote: > In the code, I create the string and use it: > ostrstream ostr(ControlString,25); > ostr.seekp(0); > ostr.width(8); > ostr.fill(0); > ostr << showbase(hex);
showbase very likely requires inclusion of <iomanip>. (<iomanip.h> if you insist on using the nonstandard headers.) Good references: The standard library documentation in VC (can be a bit cryptic, but still useful as a reference) "The C++ Standard Library: A Tutorial and Reference" by Josuttis and I believe there's an iostreams book by Langer and Kreft that's also recommended.
|
Sun, 27 Feb 2005 21:45:30 GMT |
|
 |
#3 / 12
|
 String Stream Formatting
|
Fri, 19 Jun 1992 00:00:00 GMT |
|
 |
Don #4 / 12
|
 String Stream Formatting
Craig, Thanks for the pointers! My use of strstrea and the .h is not so much a design decision on my part, more a ignorant cobbling together of examples!! Having said that, I put #include <sstream> in my header file and changed the main code to: ostringstream ostr; per an example out of Stroustrup (3rd Edition). But now I get: error C2065: 'ostringstream' : undeclared identifier I have tried a variety of permutations and have looked through the MSDN with no luck. Is this a namespace problem? Should there be other #includes (like <iomanip> in your original reply)? I am perplexed! Thanks!! Don
Quote:
> > This is my first foray into the world of streams and formatting, so maybe I > > just do not get the fundamentals. However, I am at a loss on where to go to > > figure this out. > > In my header I include the string stream class: > > #include <strstrea.h> > I would strongly recommend using <sstream> (which, incidentally, will > put everything in the standard namespace). strstreams are deprecated > and should be avoided absent a specific need. And if you still want > to use strstreams, you should use <strstream>, not the .h version. > > In the code, I create the string and use it: > > ostrstream ostr(ControlString,25); > > ostr.seekp(0); > > ostr.width(8); > > ostr.fill(0); > > ostr << showbase(hex); > showbase very likely requires inclusion of <iomanip>. (<iomanip.h> if > you insist on using the nonstandard headers.) > Good references: > The standard library documentation in VC (can be a bit cryptic, but > still useful as a reference) > "The C++ Standard Library: A Tutorial and Reference" by Josuttis > and I believe there's an iostreams book by Langer and Kreft that's > also recommended.
|
Sun, 27 Feb 2005 23:58:04 GMT |
|
 |
Carl Danie #5 / 12
|
 String Stream Formatting
Quote: > ostringstream ostr;
std::ostringstream ostr; -cd
|
Mon, 28 Feb 2005 00:16:59 GMT |
|
 |
Craig Power #6 / 12
|
 String Stream Formatting
Quote:
> Thanks for the pointers! My use of strstrea and the .h is not so much a > design decision on my part, more a ignorant cobbling together of examples!! > Having said that, I put > #include <sstream> > in my header file and changed the main code to: > ostringstream ostr;
std::ostringstream ostr; Or else you need a using directive after including <sstream> Quote: > per an example out of Stroustrup (3rd Edition). But now I get: > error C2065: 'ostringstream' : undeclared identifier > I have tried a variety of permutations and have looked through the MSDN with > no luck. Is this a namespace problem? Should there be other #includes > (like <iomanip> in your original reply)?
The only thing you'd need <iomanip> for is if you use manipulators. It's certainly not required for declaring an instance of a stringstream.
|
Mon, 28 Feb 2005 00:15:25 GMT |
|
 |
#7 / 12
|
 String Stream Formatting
|
Fri, 19 Jun 1992 00:00:00 GMT |
|
 |
Don #8 / 12
|
 String Stream Formatting
Craig & Carl, Okay, I am now making some progress. Turns out to be a namespace problem. I added a std:: to the ostringstream and things started getting better!! Looks like my problems are centering around namespaces (something I have avoiding learning ....... until now!). **-> Why, when I was using #include <strstrea.h>, did it not complain about not having the std:: before the ostrstream? Is the difference between <*.h> and <*> form for include the fact that the latter requires namespace resolution? Well, now that I have it compiling with the new stream stuff, I have to figure out why everything else now doesn't work! Argh!! Anyway, thanks for your help! I think I might be getting enough of a grasp on this to be able to ask stupid questions instead of truly idiotic ones!! Thanks! Don
Quote: > Craig, > Thanks for the pointers! My use of strstrea and the .h is not so much a > design decision on my part, more a ignorant cobbling together of examples!! > Having said that, I put > #include <sstream> > in my header file and changed the main code to: > ostringstream ostr; > per an example out of Stroustrup (3rd Edition). But now I get: > error C2065: 'ostringstream' : undeclared identifier > I have tried a variety of permutations and have looked through the MSDN with > no luck. Is this a namespace problem? Should there be other #includes > (like <iomanip> in your original reply)? > I am perplexed! > Thanks!! > Don
> > > This is my first foray into the world of streams and formatting, so > maybe I > > > just do not get the fundamentals. However, I am at a loss on where to > go to > > > figure this out. > > > In my header I include the string stream class: > > > #include <strstrea.h> > > I would strongly recommend using <sstream> (which, incidentally, will > > put everything in the standard namespace). strstreams are deprecated > > and should be avoided absent a specific need. And if you still want > > to use strstreams, you should use <strstream>, not the .h version. > > > In the code, I create the string and use it: > > > ostrstream ostr(ControlString,25); > > > ostr.seekp(0); > > > ostr.width(8); > > > ostr.fill(0); > > > ostr << showbase(hex); > > showbase very likely requires inclusion of <iomanip>. (<iomanip.h> if > > you insist on using the nonstandard headers.) > > Good references: > > The standard library documentation in VC (can be a bit cryptic, but > > still useful as a reference) > > "The C++ Standard Library: A Tutorial and Reference" by Josuttis > > and I believe there's an iostreams book by Langer and Kreft that's > > also recommended.
|
Mon, 28 Feb 2005 00:45:59 GMT |
|
 |
Carl Danie #9 / 12
|
 String Stream Formatting
Quote: > **-> Why, when I was using #include <strstrea.h>, did it not complain about > not having the std:: before the ostrstream? Is the difference between <*.h> > and <*> form for include the fact that the latter requires namespace > resolution?
Correct - the old (pre standard) classes were not in the std namespace. The same relatinship exists between the classes declared in <iostream> versus those declared in <iostream.h>. -cd
|
Mon, 28 Feb 2005 01:05:53 GMT |
|
 |
Craig Power #10 / 12
|
 String Stream Formatting
Quote:
> **-> Why, when I was using #include <strstrea.h>, did it not complain about > not having the std:: before the ostrstream? Is the difference between <*.h> > and <*> form for include the fact that the latter requires namespace > resolution?
That's the most obvious difference, but hardly the only one. Note that the <*> form is the standardized form. The <*.h> is older and pre-standard, and what you get with those headers can vary from compiler to compiler. As of VC7, Microsoft has signalled their intention to delete the <*.h> form of the iostreams from future releases.
|
Mon, 28 Feb 2005 02:32:01 GMT |
|
 |
#11 / 12
|
 String Stream Formatting
|
Fri, 19 Jun 1992 00:00:00 GMT |
|
 |
Don #12 / 12
|
 String Stream Formatting
Thanks Carl & Craig! Don
Quote: > Craig & Carl, > Okay, I am now making some progress. Turns out to be a namespace problem. > I added a std:: to the ostringstream and things started getting better!! > Looks like my problems are centering around namespaces (something I have > avoiding learning ....... until now!). > **-> Why, when I was using #include <strstrea.h>, did it not complain about > not having the std:: before the ostrstream? Is the difference between <*.h> > and <*> form for include the fact that the latter requires namespace > resolution? > Well, now that I have it compiling with the new stream stuff, I have to > figure out why everything else now doesn't work! Argh!! > Anyway, thanks for your help! I think I might be getting enough of a grasp > on this to be able to ask stupid questions instead of truly idiotic ones!! > Thanks! > Don
> > Craig, > > Thanks for the pointers! My use of strstrea and the .h is not so much a > > design decision on my part, more a ignorant cobbling together of > examples!! > > Having said that, I put > > #include <sstream> > > in my header file and changed the main code to: > > ostringstream ostr; > > per an example out of Stroustrup (3rd Edition). But now I get: > > error C2065: 'ostringstream' : undeclared identifier > > I have tried a variety of permutations and have looked through the MSDN > with > > no luck. Is this a namespace problem? Should there be other #includes > > (like <iomanip> in your original reply)? > > I am perplexed! > > Thanks!! > > Don
> > > > This is my first foray into the world of streams and formatting, so > > maybe I > > > > just do not get the fundamentals. However, I am at a loss on where to > > go to > > > > figure this out. > > > > In my header I include the string stream class: > > > > #include <strstrea.h> > > > I would strongly recommend using <sstream> (which, incidentally, will > > > put everything in the standard namespace). strstreams are deprecated > > > and should be avoided absent a specific need. And if you still want > > > to use strstreams, you should use <strstream>, not the .h version. > > > > In the code, I create the string and use it: > > > > ostrstream ostr(ControlString,25); > > > > ostr.seekp(0); > > > > ostr.width(8); > > > > ostr.fill(0); > > > > ostr << showbase(hex); > > > showbase very likely requires inclusion of <iomanip>. (<iomanip.h> if > > > you insist on using the nonstandard headers.) > > > Good references: > > > The standard library documentation in VC (can be a bit cryptic, but > > > still useful as a reference) > > > "The C++ Standard Library: A Tutorial and Reference" by Josuttis > > > and I believe there's an iostreams book by Langer and Kreft that's > > > also recommended.
|
Mon, 28 Feb 2005 03:33:44 GMT |
|
|
|