i need help with user input text file using pointer.

Hello everybody,
1. in case adding : I have a vector and a pointer that store data from input user from a class student. But I found difficult to store data into my text file and output those new data for reading. hope someone could gave me a hint or fix my wrong code. Thank you so much.
2. in case reading: if i have function line 52, i would not open the output of the text file. i really don't know reason why, please someone help me also, thank u so much.


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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  class student
{
private:
	string sname;
	int sid;
	string sclasses;

public:
	student();
	student(string, int);
	student(string, int, string);
	string getsname()const;
	int getsid()const;
	string getsclasses() const;

	void setsname(string);
	void setsid(int);
	void setsclasses(string);
	void printinfo();
};

int main()
{
	student S;
	string line, x;
	int id; 
	int iline = 0;
	int z = 1;
	int istudent,iclass;
	vector <int> Number;
	ifstream inputfile;
	ofstream outputfile;
	string data, svalue, sline, name, classes;
	// Create a vector of student objects
	vector <student> vstudent;
	student *Student = nullptr;
	Student = &S;
	const char Reading = 'A', Adding = 'B';
	do
	{displaymenu();
		cout << "Please select an option: ";
		getline(cin, svalue);
		switch (toupper(svalue[0]))
		{

		case Reading:
			cout << "\n\n enter the password: ";
			getline(cin, data);
			//int number;
			inputfile.open(data.c_str());

			/*while (getline(inputfile, sline))
			++iline;
			cout << "\nThe number of student has the size of: " << iline << endl;
			*/

			while (!inputfile)
			{
				inputfile.clear();
				cout << "\n File open failure! Please re-enter password: ";
				getline(cin, data);
				inputfile.open(data.c_str());
			}
			cout << "\nOpen successfully! \n\n";
			//	Numberstudent(iline);






			while (getline(inputfile, svalue))
			{
				cout << svalue << endl;
			}

			inputfile.close();
			break;


		case Adding:
			outputfile.open("CISC_192.txt");
			cout << "\nHow many student would you like to add: ";
			cin >> istudent;
			cin.ignore();
			for (int i = 0; i < istudent; i++)
			{
				cout << "\nplease enter the Student's Name: " << "\t";
				cin>>name;
				S.setsname(name);
				Student->setsname(name);
				
				
				cout << "\nPlease enter the Student's ID: " << "\t\t";
				cin >> id;
				S.setsid(id);
				Student->setsid(id);
				
				cout << "\nHow many classes do you want to add: " << "\t";
				cin >> iclass;
				for (int i = 0; i < iclass; i++)
				{
					cout << "\nPlease enter the student's class: " << "\t";
					cin >> classes;
					S.setsclasses(classes);
					Student->setsclasses(classes);
				}
				  
				cout << "\n";
}
			outputfile << Student << endl;
			
			while (getline(inputfile, x ))
			{
				cout << x << endl;
			}

			inputfile.close();
			



			break;
default:
			cout << "\ninvalid input";
		}
	} while (svalue[0] != Ending);
Last edited on
Why do you have a pointer?
keskiverto, my bad , i make a wrong coding by using pointer in this case. sorry about that, let me fix my code.
Last edited on
Topic archived. No new replies allowed.