Skip to main content
gamedev.net
🔒 Locked

Problems including string-class

Started by _Danneman_ Jan 11, 2004 at 8:58 AM 8 replies 2.4k views
Original Post
_Danneman_
_Danneman_
Hi, I have Visual C++ 6.0 installed. I installed MSDN libraries afterwards (they should be included automatically into VC++ 6.0 once you do that, right?) Anyway, I cant get the class "string" to work. Including... #include <string> ..or.. #include <string.h> ..or.. #include <cstring> ..doesnt make the following simple creation of a string-object to work.. string myString; Any idea as to what might be wrong? Thanks
------------------------Why of course the people don’t want war. ... That is understood. But after all it is the leaders of the country who determine the policy, and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship ...Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is to tell them they are being attacked, and denounce the pac
SiCrane
SiCrane
The string class lives in namespace std. To use it either declare your string like:
std::string myString
or use a using directive in your source code like:
using namespace std; or using std::string;
Thunder_Hawk
Thunder_Hawk
In addition, the necessary include line is:
#include <string>

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
_Danneman_
_Danneman_
Thanks guys
------------------------Why of course the people don’t want war. ... That is understood. But after all it is the leaders of the country who determine the policy, and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship ...Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is to tell them they are being attacked, and denounce the pac
_Danneman_
_Danneman_
Still got a problem, unfortunately:

Is there any reason why this simple sample code should not work?
---------------------------------------
#include <iostream.h>
#include <string>
using namespace std;

void main(){

string word;

cout << "Enter word: ";

cin >> word;

cout << word;
}
----------------------------------------

I get the following 2 error-messages:

1) error C2679: binary ''>>'' : no operator defined which takes a right-hand operand of type ''class std::basic_string,class std::allocator >'' (or there is no acceptable conversion)

2) error C2679: binary ''<<'' : no operator defined which takes a right-hand operand of type ''class std::basic_string,class std::allocator
>'' (or there is no acceptable conversion)
------------------------Why of course the people don’t want war. ... That is understood. But after all it is the leaders of the country who determine the policy, and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship ...Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is to tell them they are being attacked, and denounce the pac
TangentZ
TangentZ
Use this:

#include <iostream> 


Notice there is no ".h".



Kami no Itte ga ore ni zettai naru!
神はサイコロを振らない!
_Danneman_
_Danneman_
Thanks

Btw, it seems that both iostream.h and iostream exists in the libraries.

How are they different (in general terms - .h vs non-.h files)?
------------------------Why of course the people don’t want war. ... That is understood. But after all it is the leaders of the country who determine the policy, and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship ...Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is to tell them they are being attacked, and denounce the pac
Thunder_Hawk
Thunder_Hawk
iostream.h is a non-standard header that was used before the standard came around to the creation of <iostream>. It's only included for backwards compatibility. You should try to use the standardized versions of headers whenever possible (99.9% of the time) to improve the portability of your code.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________


[edited by - Thunder_Hawk on January 11, 2004 11:17:39 AM]
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
_Danneman_
_Danneman_
Great info - strings are working perfectly now.

Thanks again
------------------------Why of course the people don’t want war. ... That is understood. But after all it is the leaders of the country who determine the policy, and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship ...Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is to tell them they are being attacked, and denounce the pac

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.