Page 1 of 1

an Ambiguity in istrstream

Posted: Thu Nov 14, 2002 7:43 pm
by Navid
//this code Don't work
//Output Should Be "Hello World " But isn't (it's nonsense or null)
[cpp]
#include<strstrea.h>
#include<string.h>
char token1[100];
char token2[500];
char first[500];//Ambiguity line
void main()
{
istrstream ST(first);
strcpy(first,"Hello World");
ST>>token1;//Part That don't work Correctly
ST>>token2;//Part That don't work Correctly
cout<<token1;
cout<<token2;
}
[/cpp]
//Output has error

//but when I move this ambiguity line : char first[500];
into the main function it works correctly

[cpp]
#include<strstrea.h>
#include<string.h>
char token1[100];
char token2[500];
void main()
{
char first[500];//Ambiguity line
istrstream ST(first);
strcpy(first,"Hello World");
ST>>token1;//Part That don't work Correctly
ST>>token2;//Part That don't work Correctly
cout<<token1;
cout<<token2;
}
[/cpp]

Anybody could Explain Difference of First code and second where I move that line?

Compiler?

Posted: Sun Nov 17, 2002 3:20 pm
by suman
Hi,
Which compiler are you using? It seems to be a compiler problem, while handling global data.

- Suman

Posted: Sun Nov 17, 2002 11:35 pm
by Navid
Visual C++ 6