Monday, May 24, 2010

When I used string data type in my c++ programme, it shows error i.e. data type expected.?

as per i know, string is also a data type, but when i declare variable with string datatype, error is data type expected, variable not declared , ect.


so, for alternative, i used char datatype, but it accepts character till space %26amp; ignore(or assign to next variable) character entered after space, plzzzzzzzzzz help me

When I used string data type in my c++ programme, it shows error i.e. data type expected.?
Are u sure ur working in c++ not vc++? In c++ string is NOT data type i am damn sure. If ur reading the chars with cin function it reads only till blank space and thinks end of string so u wont get anything after space. Instead u use getche() function. This program is nothing to do with string.h. include string.h for strcmp,strlen etc function if required.
Reply:There Is U Haven't Included #include%26lt;string.h%26gt; Else There Is No Error,Means U May Haven't Included..
Reply:If you are using the STL string class then you probably want to add at the top:





#include %26lt;string%26gt;





and:





using namespace std;
Reply:Hmm...do you have to #include string.h?





The char datatype only takes one character. If you're looking to store words or phrases, you should use a string. What does the error message say exactly, and what syntax are you trying to use to declare the string?


No comments:

Post a Comment