Jump to content
  • Advertisement
Sign in to follow this  
Zaris

cin.get

This topic is 4235 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having trouble with this code
int menu::open()
{
	display();
	char choice=' ';
	std::cout<<"Enter Selection: ";
	
	std::cin.get(choice);
	std::cin.ignore();
	
	std::cout<<choice<<std::endl;
	std::vector<menuoption>::iterator myiter;
	for(myiter=optionlist.begin();myiter<optionlist.end();myiter++)
	{
		
		if(choice==myiter->getChoice())
			return myiter->getReturnvalue();
	}
it works, until I try to input more then one char; Then it will still loop, but will not take any new input.

Share this post


Link to post
Share on other sites
Advertisement
Im no c++ master, but i dont think you can hold more than 1 charater in the char-type without a array... include <string> and decalre choice as string

#include<string>
int menu::open()

{

display();

string choice=' ';

std::cout<<"Enter Selection: ";



std::cin.get(choice);

std::cin.ignore();



std::cout<<choice<<std::endl;

std::vector<menuoption>::iterator myiter;

for(myiter=optionlist.begin();myiter<optionlist.end();myiter++)

{



if(choice==myiter->getChoice())

return myiter->getReturnvalue();

}

Share this post


Link to post
Share on other sites
Just what he said

#include <iostream>
#include <string>

using namespace std;

int main()
{
string VariableName = "";
cout << "Enter Selection: ";
cin >> VariableName;
return 0;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!