hi

I'm new to C++ and was wondering if it is possible to create variables in runtime.

example:

If I ask how many patiënts have to be operated, the program should create a variable for each patiënt that can contain their individual data.

thx

hi

If I ask how many patiënts have to be operated, the program should create a variable for each patiënt that can contain their individual data.

You could use vectors to store pointers to 'patient'classes. That way you could 'create' patients at runtime.

Regards Niek

If I ask how many patiënts have to be operated, the program should create a variable for each patiënt that can contain their individual data.

A simple, crude, sample program:

#include <iostream>
#include <vector>

int main()
{
    using namespace std;

    int count = 0 ;
    vector<int> vec_int ;

    cout << "Enter the number of patients you want: " ;
    cin >> count ;
    getchar() ;

    for( int i = 0; i < count; ++i )
    {
        vec_int.push_back(i+1) ;
    }

    cout << "\nNow displaying the contents: \n" ;

    for( int i = 0; i < count; ++i )
    {
        cout << vec_int[i] << endl ;
    }

    cin.get() ;
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.