Read strings and bool from txt

Hello !

I have array of struct and i want
1] when i run the program to load the data from it.
2] when i make changes to be saved in the text file the same time or when i quit the program

I tried to put data in txt file with the following format but i can only read until the space. I do a lot of search but wasn`t able to find what i look for. Mainly i don`t know how to read strings

A1 false Alexa Trina
A2 falseGeorge Ali
A3 false Comina Riviera

My sample code is:
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
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

class classroom
{
public:
    string studentClass;
    bool studentBonus;
    string studentName;

    void classroom::createStudent(string sClass, bool bonus, string name);
};

void classroom::createStudent(string sClass, bool bonus, string name)
{
    studentClass=sClass;
    studentBonus=bonus;
    studentName=name;
}

int main()
{
    //number of students
    const int numstudents=10;
    
    //create structure
    classroom student[numstudents];

    //initialize variables
    student[0].createStudent("A1",false,"Alexa Trina");
    student[1].createStudent("A2",false,"George Ali");
    student[2].createStudent("A3",false,"Comina Riviera");

    return 0;//indicate that program end succesfully
}//end main  

Thanks for your time!
Last edited on
Topic archived. No new replies allowed.