Search
 
SCRIPT & CODE EXAMPLE
 

CPP

read struct from file c++

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct patientRec {
	int id;
	string firstName;
	string lastName;
	float height;
	float weight;
};
int main() {
	patientRec patient;
	fstream file;
	file.open("Patient record.txt", ios::in);
	cout << "Patient record file: 
";
	if (file.is_open()) {
		file >> patient.id >> patient.firstName >> patient.lastName >> patient.height >> patient.weight;
		cout << "ID: " << patient.id << endl;
		cout << "First name: " << patient.firstName << endl;
		cout << "Last name: " << patient.lastName << endl;
		cout << "Height: " << patient.height << endl;
		cout << "Weight: " << patient.weight << endl;
      	file.close();

	}
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: what is __asm in C++ 
Cpp :: create a dictionary cpp 
Cpp :: loop through char in string c++ 
Cpp :: format string cpp 
Cpp :: c++ matrix as argument 
Cpp :: how to get a letter from the user c++ string 
Cpp :: convert int to string c++ 
Cpp :: C++ convert vector of digits into integer 
Cpp :: apply pca to dataframe 
Cpp :: min vector c++ 
Cpp :: how to read a comma delimited file into an array c++ 
Cpp :: how to compare lower case character to uppercase cpp 
Cpp :: how to open and read text files in c++ 
Cpp :: C++ do...while Loop 
Cpp :: c++ declare variable 
Cpp :: take pieces of a string in c++ 
Cpp :: C++ Find the sum of first n Natural Numbers 
Cpp :: Heap pinter c++ 
Cpp :: ue4 c++ enumaeration 
Cpp :: doubly linked list c++ code 
Cpp :: find primes in cpp 
Cpp :: overload stream insert cpp 
Cpp :: how to get the first element of a map in c++ 
Cpp :: inbuilt function to convert decimal to binary in c++ 
Cpp :: check if a string is palindrome cpp 
Cpp :: length of array in cpp 
Cpp :: time of a loop in c++ 
Cpp :: how to sort in c++ 
Cpp :: c++ add to array 
Cpp :: cpp vs c# 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =