May 2, 2002 #1 ARCITS Programmer Apr 4, 2002 99 GB In VB you can write: string("=",20) to generate the string "====================" Is there an equivalent in C++?
In VB you can write: string("=",20) to generate the string "====================" Is there an equivalent in C++?
May 2, 2002 #2 Leibnitz Programmer Apr 6, 2001 393 CA #include<iostream.h> void String( char *caracter, int number ) { for( int i = 0; i < number; i++ ) cout<<caracter; } void main() { String( "=" , 20 ); } Upvote 0 Downvote
#include<iostream.h> void String( char *caracter, int number ) { for( int i = 0; i < number; i++ ) cout<<caracter; } void main() { String( "=" , 20 ); }
May 2, 2002 #3 Leibnitz Programmer Apr 6, 2001 393 CA Or maybe this will do: #include<iostream.h> #define _MAXSTRING_ 100 char* string; void String( char character, int number ) { string = new char[_MAXSTRING_]; for( int i = 0; i < number; i++ ) string = character; string = '\0'; } void main() { String( '=' , 20 ); cout<<string; delete string; } Upvote 0 Downvote
Or maybe this will do: #include<iostream.h> #define _MAXSTRING_ 100 char* string; void String( char character, int number ) { string = new char[_MAXSTRING_]; for( int i = 0; i < number; i++ ) string = character; string = '\0'; } void main() { String( '=' , 20 ); cout<<string; delete string; }
May 2, 2002 #4 Zyrenthian Programmer Mar 30, 2001 1,440 US there is a much easier way first you need to remember to have it have an extra character for the null terminator and just do char buffer[21]; memset(buffer,'=',20); buffer[20]=0; Matt Upvote 0 Downvote
there is a much easier way first you need to remember to have it have an extra character for the null terminator and just do char buffer[21]; memset(buffer,'=',20); buffer[20]=0; Matt