I am doing this
char *draw_line(int n, char ch)
{
char *line = new char[50];
for(int i = 0; i <= n; i++)
line[i] = ch;
return line;
}
and while calling the function I am writing this:
char *res_line = draw_line(50, '=');
cout<<*res_line;
but instead of getting = printed 50 times in the console window, it just show = sign one time. My main aim is to return the = or any character as many times I want and output
the same to a text file. That's it.
std::stringnand50are secretly related, you're right. once you fix the terminator, trycout << ch50. And plz consider just usingstd::string(50,ch). Use the standard lib. It's whats for dinner.std::stringbecause it can be safer and more versatile (and because C++ standard); however, if you want to use char[] or char*, then more power to you in my opinion. It just means you may run into more problems to overcome. A learning experience, if you ask me.std::stringis that it won't leak memory. (Of course, if he can accept a maximumn, it's possible to write a thread safe version using a static variable, and avoid all dynamic allocation completely.)