Problem with string getline and alignment

Hello. Im using string to get and input for studentID and studentname but there seems to be an error when I run the program.
I want to have the studentID entered before getting prompt for studentname input however my program prompts both studentID and Studentname at the same time such that I have to input both at the same time.

This is a partial bit of the student class i did:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include "student.h"
using namespace std;

student::student(char stype)
{
	set_StudentType(stype);
}

void student::set_StudentID()
{
	cout << "Key in student's ID: \n";
	getline(cin, studentid, '\n');
}
void student::set_Name()
{
	cout << "Key in student's name: \n";
	getline(cin, studentname, '\n');
}
string student::get_StudentID()
{
	return studentid;
}
string student::get_Name()
{
	return studentname;
}
}


and this is part of the main program where I output to a text file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
if ( DorS == 'D' )
{
	academicdiploma student;

	student.set_StudentID();
	student.set_Name();
	student.set_NoOfSubjects();

	outfile << left << student.get_StudentID() << setw(10) << student.get_Name()
		<< setw(35) << student.get_StudentType() << setw(10) 
		<< student.get_SkillArea() << setw(15) << student.get_NoOfSubjects() 
		<< setw(5) << student.get_Result() << endl;

}
else
{
	skillscertificate student;

	student.set_StudentID();
	student.set_Name();
	student.set_SkillArea();

	outfile << left << student.get_StudentID() << setw(10) << student.get_Name()
		<< setw(35) << student.get_StudentType() << setw(10) 
		<< student.get_SkillArea() << setw(15) << student.get_NoOfSubjects()
		<< setw(5) << student.get_Result() << endl;
}

The alignment problem is seen when I output all these to the textfile. It doesn't align properly.
Can anyone enlighten me?
Last edited on
Topic archived. No new replies allowed.