#### Archived

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.

## 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 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 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 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.

Thanks.

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011470
• ### Who's Online (See full list)

There are no registered users currently online

×