On 16 Aug., 17:09, wang <king_ww...@yahoo.de> wrote:
> On 15 Aug., 22:23, "Francesco S. Carta" <entul...@gmail.com> wrote:
>
>
>
>
>
> > > #include<string>
> > > #include<sstream>
> > > #include<iostream>
> > > using namespace std;
> > > int main() {
> > > * *double x = 1.2, y = 6.5;
> > > * *string xs, ys;
> > > * *ostringstream oss;
> > > * *oss<< *x;
> > > * *xs = oss.str();
> > > * *oss.str(string());
> > > * *oss<< *y;
> > > * *ys = oss.str();
> > > * *cout<< *xs<< *endl;
> > > * *cout<< *ys<< *endl;
> > > * *return 0;
> > > }
>
> > Just for the records, notice that your original solution would have
> > worked fine - quoting your words from the original post:
>
> > > I inserted "oss.str("");" before "oss << y;",
>
> > oss.str("");
>
> > and
>
> > oss.str(string());
>
> > achieve just the same result.
>
> > Hence there must have been some other problem hanging around when you
> > posted your original question.
>
> I'm to 99% certain that you are right. Neither oss.str("") nor
> oss.str(string()) works with MS VC++6. On Ubuntu Linux with g++,
> oss.str(string()) works just fine. I've forgotten if I've tested with
> oss.str("") on Linux.
> Since I realized that VC++6 doesn't work with ostringstream this way,
> I went back to ANSI C and used sprintf() to fulfil my task. I wanted
> to write "pure" C++ code, but VC++6 doesn't let me do it.
> kwwang- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
On Ubuntu Linux with g++, oss.str("") works fine, too.
kwwang
|