Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


getline problems

This topic is 5278 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

void set_characterNameAgeSex()
	char setName[ 50 ];
	char *sTransfer;
	short setSex;
	short setAge;

	// set name

	cout << "Enter a name for your character(50 char. max): ";
	cin.getline( setName, 49 );

	sTransfer = setName;
	sName[ 0 ] = sTransfer;

	// age choice

	cout << "\nEnter an age for your character( 17-45 ): ";
	cin >> setAge;
I can''t figure out why the program is skipping the line: cin.getline( setName, 49 ); It prints the cout before that but skips user input.... also, I''ve fixed the bugs for VC++6.0 related to istream and string. but also I was wondering, it says to replace snextc with sbumpc but since I have VC++ 6.0, I changed it to stossc. Do I change just that one line, or should I change all the snextc''s to stossc? also, in my file, there is a line like this: else if (_Tr::eq((_E)_C, _D)) but the fixes page has the line like this: else if (_Tr::eq(_C, _D)) should I change it or leave it? thanks.

Share this post

Link to post
Share on other sites
look into using cin.ignore() member function. What may be happening is that the call from getline is still leaving the newline on the stream and thats why its not getting your user input properly.

Share this post

Link to post
Share on other sites
it works if i put cin.ignore....but why? What is wrong with the getline function?

Maybe I should reinstall VC++6.0....

Share this post

Link to post
Share on other sites

#include <iostream>

using namespace std;

char *hstring[ 1 ];

int main()
char *s1;
char name[ 50 ];

cout << "Enter a string: ";
cin.getline( name, 49 );

s1 = name;
hstring[ 0 ] = s1;

cout << "\n" << hstring[ 0 ] << endl;

return 0;

One thing I noticed: For the above code, when I put my mouse over hstring[ 0 ] in the line
hstring[ 0 ] = s1; it shows a tooltip that says "char *hstring[1]". But when I put my mouse over sName[ 0 ], it says "char sName[50].

What do you think the problem is?

There really is no difference between the two code as far as I can tell besides variable names.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!