Array of chars, wtf?

Hey! Could someone help me with an array of characters?
I need to make an array of stars (*) that corresponds to a number that an user types in, something like this:

chars = 4;
int length [chars] = "*";

^ this however, doesn't compile. I need the length array contain 4 stars.

Please reply.
You need a dynamic array:
1
2
int length = 4;
char *chars = new char[length];

http://www.cplusplus.com/doc/tutorial/dynamic/

Or a string:
1
2
int length = 4;
string chars(4,'*');

http://www.cplusplus.com/reference/string/string/string/
Last edited on
this is the code im using

1
2
3
4
5
6
7
8
9
int chars;  
      
cout<<"Enter a number: ";
cin>>chars;


string length = (chars,'*');
cout<<length;


It doesnt compile, says invalid conversion between char and const char*
Remove the equals sign on line 7
Thanks bazzy, you're amazing!
Topic archived. No new replies allowed.