Help with variable size

Hello people,

I am currently working with C++ console application(VS2012) to get input from user and I have couple question related to it.

1. Is there a way of declaring char type array with varying size?(You will understand what I mean after looking at my code)

2. Assuming that there is no such way for #1, what shall I do? If I declare it something shorter than input, then it gives me run time check failure.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
char name[] = "                                            ";
	char address[] = "                                            ";
	char school[] = "                                   ";
	char age[] = "  ";
	double myVisit;
	double ofc;
	int a;
	cout << "What is your name?";
	cin.getline(name, 100);
	cout << "What is your age?";
	cin.getline(age,10);
	cout << "What school do you attend?";
	cin.getline(school, 100);
	cout <<"What is your address?";
	cin.getline(address,30);
	cout <<"How many times have you went to see?";
	cin >> myVisit;
	cout<<"How many times have I?";
	cin >> ofc;
	cout <<"Which option would you like? 1. Optimistic\n 2. Pessimistic";
	cin >> a;


Please give me some advice! Thank you in advance for replies
If you use such form of getline as

cin.getline(name, 100);

then it is enogh to declare a character array of size 100.

Otherwise you can use standard C++ class std::string.
Topic archived. No new replies allowed.