an Ambiguity in istrstream

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
Navid
New poster
Posts: 4
Joined: Sun Nov 03, 2002 9:19 pm
Location: University of Tehran-Tehran-Iran
Contact:

an Ambiguity in istrstream

Post 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?
suman
New poster
Posts: 45
Joined: Fri Oct 19, 2001 2:00 am
Contact:

Compiler?

Post by suman »

Hi,
Which compiler are you using? It seems to be a compiler problem, while handling global data.

- Suman
Navid
New poster
Posts: 4
Joined: Sun Nov 03, 2002 9:19 pm
Location: University of Tehran-Tehran-Iran
Contact:

Post by Navid »

Visual C++ 6
Post Reply

Return to “C++”