Skip to main content
GameDev.net gamedev.net
🔒 Locked

std::string

Started by whats a username Oct 8, 2001 at 6:37 PM 2 replies 450+ views
Original Post
whats a username
whats a username
How can I input into a std::string using cin? Edited by - whats a username on October 8, 2001 7:54:01 PM
SPAR
SPAR
#include string.h
#include iostream

void main()
{
using namespace std;
string str;
cin >> str;
cout << str; // this prints your string back to you
system("pause");
}

Edited by - SPAR on October 8, 2001 8:38:50 PM
whats a username
whats a username
I tried that before asking this question. It doesn't work.

d:\test std string\main.cpp(8) : 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 accept
able conversion)
d:\test std string\main.cpp(9) : 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 accept
able conversion)

Edited by - whats a username on October 8, 2001 8:43:11 PM
NuffSaid
NuffSaid
  
#include <iostream>
#include <string> //it is string, not string.h


using namespace std;

int main(void)
{
string str;

cout<<"Enter a string : ";
cin>>str;
cout<<"Content of string is : " <<str <<endl;

return 0;
}


That should work. I don''t have a compiler with me at the moment to verify it though.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.

Topic Locked

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

Sign in to reply to this topic.