Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

read and write objects in cpp

#include <iostream>
#include <fstream>
using namespace std;

class student
{
public:
    char name[20], id[10], level[10];

    void getdata()
    {
        cout <<" Enter your name: ";
        cin >> name;

        cout <<" Enter your id: ";
        cin >> id;

        cout <<" Enter your level: ";
        cin >> level;
    }
};

int main()
{
    student s1,s2;

    s1.getdata();
    cout<< endl;
    s2.getdata();

    ofstream file_w ("obj.txt");
    file_w.write((char *)&s1, sizeof(s1));
    file_w.write((char *)&s2, sizeof(s2));

    cout<< "successfully written in file
";
    file_w.close();

    ifstream file_r ("obj.txt");
    file_r.read((char *)&s1, sizeof(s1));

    cout<< "successfully read file
";

    char text[100];
    while(file_r)

    {
        file_r.getline(text,100);
        cout << text <<endl;
    }
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: how to call an action from another action slice in redux 
Typescript :: different keymaps in the following locations 
Typescript :: Define a function shiftRight which receives a list as input, and returns a list with all the elements shifted to the right 
Typescript :: combine results from two columns in ms sql 
Typescript :: typescript event emitter 
Typescript :: requierd one of two attribute in obj js ts 
Typescript :: submit with data and event in child to parent 
Typescript :: does pure water contain natturaly occuring minerals? 
Typescript :: template matching several bounding boxes outputted need only one 
Typescript :: how to add every two elements in python 
Typescript :: how to gray out the unused imports in vscode 
Typescript :: display only user contributor comments wordpress 
Typescript :: convert f# 
Typescript :: sql delete all tables starts with 
Typescript :: number of increments and decrements to make array sorted 
Typescript :: how to pass data between requests in api 
Typescript :: header elements on right 
Typescript :: phase on load complete 
Typescript :: Defects and Defect Density of quality software 
Typescript :: Job for pm2-rfb.service failed because the service did not take the steps required by its unit configuration. 
Typescript :: omgsmhwthwhyomgnvm 
Typescript :: ht office 
Typescript :: how to take list as command line arguments in python 
Typescript :: for loop of unlimited inputs python 
Typescript :: check if all elements in array can be divided by python 
Typescript :: is subscribing to a lot of events in ngonint bad 
Typescript :: add hsts domain 
Typescript :: Types and CoProducts in scala 
Typescript :: how to set references in sequelize type config/options 
Typescript :: how many type of mosfet are there 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =