write a program to store the data of mobile shop in a file with appropriate data members and member functions. use read and writes method to perform the file operations. read only the price and model value of mobile from file.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main() {
string fileName="mobiles.txt";
ifstream mobilesFstream(fileName);
if(!mobilesFstream){
cout << "The file '"<<fileName<<"' does not exist.\n";
}else{
string model;
float price;
while(!mobilesFstream.eof()){
mobilesFstream>>price;
getline(mobilesFstream,model);
cout<<"Model: "<<model;
cout<<", price: "<<price<<"\n";
}
}
mobilesFstream.close();
cin>>fileName;
return 0;
}
The filename "mobiles.txt"
45.99 Samsung Galaxy F62
15.99 Nokia X4
20.99 Nokia H5
Comments
Leave a comment