SIMPLE Dynamic char array

I am trying to get user input and create an array with the length of char entered.

Instead of:


1
2
3
4
5
6
7
8
const int MAX = 3000;
char msg[MAX];

cout << "Enter a sentence";
	
cin.clear();
cin.width(MAX);
cin.getline(msg, MAX);


Without using strings, I would like to do this: Where ? will be the number of characters entered?

1
2
3
4
5
6
7
const int MAX = ?;
char msg[?];

cout << "Enter a sentence";

...
1
2
3
4
5
int size;
cout << "How big?";
cin >> size;

char* pArray = new char[size];


A better opiton would be to use a proper C++ container such as vector that handles its own size.
@Moschops I think the purpose is not to ask the user how many characters they intend to enter.
@OP Why are you against std::string?
Last edited on
Topic archived. No new replies allowed.