Static struc

Hello,

I have this struct
1
2
3
4
5
6
7
8
9
10
11
12
static struct {
  int value1;
  int value2;
  int used;
} data[] = {
  { 1, 2 },
  { 1, 3 },
  { 1, 4 },
  { 2, 5 },
  { 3, 4 },
  { 3, 5 },
};


Is it possible to ask the user to input the values of data[] or maybe use an input file?

cheers!
Sure it is. You can get integer values from the user (at the console) using std::cin, or read it from a file instead (see here: http://cplusplus.com/doc/tutorial/files/; once you've opened a file, simple I/O of integers should be very similar to cin anyway).

Then if you want to change the values of elements of data, just do something like this:
data[index].value1 = your_value;
where obviously, you give index and your_value particular values.

Just, note that if you don't initialize data with any values to start with, you would have to specify its size in its declaration.

Hope this helps.
Topic archived. No new replies allowed.