0

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

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by flageolet
0

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

0

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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.