English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm having a problem like so.

stream>>FirstName;
stream>>LastName;
stream>>IDnum;
cout<
Instead of outputting something such as

John Smith 45

It outputs this...

45n Smith

For some reason, after the LastName is printed, it goes to the beginning of the buffer and writes over the characters. FirstName and LastName are character arrays and not a strings, and that's what they have to be (class assignment). I've tried flush between LastName and IDnum, but that doesn't seem to work. Whats the problem?

2006-11-19 07:44:12 · 2 answers · asked by Harb Frame 3 in Computers & Internet Programming & Design

Initiation statements...

char FirstName[10],LastName[15];
int IDnum;

when it reads the stream, not all of the slots in the array are filled, for instance, when "john" is read, only the first 4 are inputted. If this happens, whats the values for the rest of the array slots?

2006-11-19 10:31:08 · update #1

2 answers

You need to show us your initiation statements for FirstName, LastName and Idnum; it looks to me that you have something mixed up while allocating memory for these variables.

2006-11-19 09:11:10 · answer #1 · answered by banan 2 · 1 1

most probably, you have not allocated memory properly for your strings.

2006-11-19 15:57:32 · answer #2 · answered by n0body 4 · 0 1

fedest.com, questions and answers