Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string output

Status
Not open for further replies.

antonaras

Programmer
Joined
Mar 7, 2006
Messages
2
Location
GB
ok simmple question
how to output a datatype of type string?
to be more specific

#include <string>

string word;
char i;
while(i=getc(pFile)!='>')
{
word += i;
}
//Here i want to output the value of word how can i do it
pls help it must be easy for u
 
Code:
cout << word << endl;
 
> while(i=getc(pFile)!='>')
You also need to fix your precedence.

What you have is
Code:
while(i = [b][COLOR=red]([/color][/b]getc(pFile)!= '>'[b][COLOR=red])[/color][/b] )
This basically causes i to have the value 1, until it matches a > at which point it has the value 0 and the loop exits.

What you're more likely to want is
Code:
while( [b][COLOR=red]([/color][/b]i = getc(pFile)[b][COLOR=red])[/color][/b] != '>' )

--
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top