Visual Studio 2017 Read Text File C++

  • #1
I am creating a program to process educatee records, only when I choose to list all the educatee records, the list shown is incomplete. I accept no idea what went wrong in my code. Whatsoever suggestions is highly appreciated. Thank you.
                              #include<iostream> #include<iomanip> #include<fstream> #include<cstring> #include<windows.h> #include<cctype>  using namespace std;  typedef struct { 	char name[50]; 	char std_ID[seven]; 	char course[50]; 	char phone[12]; 	char accost[100]; 	char email[100]; 	char subject1[50]; 	char subject2[50]; 	char subject3[50]; 	char subject4[50]; 	char subject5[50]; 	char grade1[iii]; 	char grade2[iii]; 	char grade3[three]; 	char grade4[3]; 	char grade5[3]; }STUDENT_PROFILE;  void list(STUDENT_PROFILE stud[], int rows); void update_grade(STUDENT_PROFILE stud[], int rows); int  searchStudent(STUDENT_PROFILE stud[], int rows); void show_user();  int main(void) { 	ifstream inFile("studentrecords.txt");  	if (!inFile) 		cout << "Error opening input file\due north"; 	else 	{  		STUDENT_PROFILE students[300]; 		int alphabetize = 0, choice;   		while (inFile) 		{  			if (inFile.peek() == '\n') 				inFile.ignore(256, '\n'); 			inFile.getline(students[index].name, l); 			inFile.getline(students[index].std_ID, vii); 			inFile.getline(students[index].course, 50); 			inFile.getline(students[index].phone, 12); 			inFile.getline(students[index].address, 100); 			inFile.getline(students[alphabetize].email, 100); 			inFile.getline(students[index].subject1, 50); 			inFile.getline(students[index].subject2, 50); 			inFile.getline(students[index].subject3, 50); 			inFile.getline(students[index].subject4, 50); 			inFile.getline(students[index].subject5, 50); 			inFile.getline(students[index].grade1, 3); 			inFile.getline(students[index].grade2, 3); 			inFile.getline(students[index].grade3, 3); 			inFile.getline(students[index].grade4, iii); 			inFile.getline(students[index].grade5, 3); 			// read next number 			index++; 		} 		inFile.close(); 		cout << "Number of student record = " << alphabetize << endl;//check number of student 															   // card starts 		do 		{ 			cout << "one. List \north"; 			cout << "3. Update student form\n"; 			cout << "4. Exit\due north"; 			cout << "Enter pick: "; 			cin >> choice;  			switch (choice) 			{ 			example 1: list(students, index); 				break; 			case two: show_user(); 				interruption; 			instance 3: update_grade(students, index); 				interruption; 			example 4: break; 			default: cout << "Invalid choice\due north"; 			} 		} while (selection != 4);  		ofstream outFile("studentrecords.txt"); 		if (!outFile) 			cout << "Fault opening output file, records are not updated.\n"; 		else 		{ 			for (int i = 0; i < index; i++) 			{ 				outFile << students[i].name << endl; 				outFile << students[i].std_ID << endl; 				outFile << students[i].course << endl; 				outFile << students[i].phone << endl; 				outFile << students[i].address << endl; 				outFile << students[i].email << endl; 				outFile << students[i].subject1 << endl; 				outFile << students[i].subject2 << endl; 				outFile << students[i].subject3 << endl; 				outFile << students[i].subject4 << endl; 				outFile << students[i].subject5 << endl; 				outFile << students[i].grade1 << endl; 				outFile << students[i].grade2 << endl; 				outFile << students[i].grade3 << endl; 				outFile << students[i].grade4 << endl; 				outFile << students[i].grade5 << endl; 			} 			outFile.close(); 		} 	} 	return 0; }  void list(STUDENT_PROFILE stud[], int rows) { 	system("cls"); 	for (int i = 0; i < rows; i++) 	{ 		cout << "Student name : " << stud[i].proper name << "\n" << "Student ID : " << stud[i].std_ID << "\n"; 		cout << "Grade : " << stud[i].course << "\n" << "Contect number : " << stud[i].telephone << "\n"; 		cout << "Address : " << stud[i].address << "\n" << "E- mail : " << stud[i].electronic mail << "\n"; 		cout << "Discipline" << setw(xx) << "Grade" << endl; 		cout << "" << stud[i].subject1 << "\t" << setw(20) << "" << stud[i].grade1 << "\n" 			<< "" << stud[i].subject2 << "\t" << setw(20) << "" << stud[i].grade2 << "\due north" 			<< "" << stud[i].subject3 << "\t" << setw(20) << "" << stud[i].grade3 << "\n" 			<< "" << stud[i].subject4 << "\t" << setw(20) << "" << stud[i].grade4 << "\north" 			<< "" << stud[i].subject5 << "\t" << setw(twenty) << "" << stud[i].grade5 << "\n" 			<< endl; 	} 	return; } void update_grade(STUDENT_PROFILE stud[], int rows) { 	cout << "examination update ok"; }  int  searchStudent(STUDENT_PROFILE stud[], int rows) { 	int cc; 	cout << "test search ok"; 	cc = 0; 	return 0; }  void show_user() { 	cout << "show user"; }                            
Here is my programme output

Educatee name : Michael J. Pull a fast one on
Pupil ID : 12022
Course : Software Engineering
Contect number : 012-4787527
Address : Amherst Street, West Bloomfield, MI
E- mail : mikej@gmail.com
Subject field Form
Basic Japanese A
Basic C++ Programming B
Database Systems Fundamenta A
Game Engine Programming A+
Statistics for Computing A

Student name : Oscar Lee
Student ID : 12044
Course : Software Technology
Contect number : 402-555-013
Accost :
Due east- mail :
Subject Grade

Michael J. Fox
12022
Software Engineering
012-4787527
Amherst Street, Due west Bloomfield, MI
mikej@gmail.com
Bones Japanese
Basic C++ Programming
Database Systems Fundamenta
Game Engine Programming
Statistics for Computing
A
B
A
A+
A
Oscar Lee
12044
Software Engineering
402-555-0139
512 Winding Way,Cranford, NJ 07016
oscarl@hotmail.com
Basic French
Basic C++ Programming
Database Systems Fundamentals
Game Engine Programming
Statistics for Calculating
A
A
B
A+
A
rgd1101
November seven, 2011
17,080
129
86,700
3,372
  • #3

The programme debugs fine, but the problem only arises after the List option in the bill of fare is chosen. It is supposed to list all the student records I have in the text file, still, in my program output, only 2 student records are listed. I can't seem to figure out what went incorrect.

rgd1101
Nov vii, 2011
17,080
129
86,700
three,372
  • #4

The program debugs fine, but the problem merely arises after the Listing pick in the menu is chosen. It is supposed to list all the student records I have in the text file, however, in my program output, only two student records are listed. I can't seem to figure out what went wrong.

I hateful debug, and stride thru your logic.
Requite you a hint, look at the 2nd phone# on the output

  • #v

The programme debugs fine, simply the problem but arises later the Listing option in the menu is called. Information technology is supposed to list all the pupil records I have in the text file, however, in my plan output, only 2 educatee records are listed. I can't seem to figure out what went incorrect.

I hateful debug, and step thru your logic.
Give you a hint, await at the 2d phone# on the output

Oh crap, I disregarded that. Cheers very much for your help.

Thread starter Like threads Forum Replies Appointment
A Apps General Discussion v
ii Apps Full general Give-and-take ane
A Apps General Word 1
T Apps General Discussion one
J Apps General Discussion 4
D Apps General Give-and-take two
arpitsri Apps Full general Word 3
A Apps General Word 10
A Apps General Discussion 5
1000 Apps Full general Give-and-take 4
R Apps Full general Discussion 4
F Apps General Word 1
Rainfire Apps General Discussion iii
Chiliad Apps General Give-and-take 4
M Apps General Discussion 2
S Apps General Discussion 4
Jaakey Apps General Discussion 2
R Apps General Give-and-take 3
P Apps General Discussion 2
O Apps General Discussion i
  • Advertisement
  • Cookies Policies
  • Privacy
  • Term & Conditions
  • Topics

Visual Studio 2017 Read Text File C++

Source: https://forums.tomsguide.com/threads/visual-studio-2015-c-text-file-reading.105232/

0 Response to "Visual Studio 2017 Read Text File C++"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel