#include <iostream>
usingnamespace std;
int main()
{
for ( int i = 1; i <= 3; i++ ) cout << "This will be printed 3 times!\n";
}
I quite like this one, too.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <string>
usingnamespace std;
string operator *( unsignedint n, string s )
{
string result;
while ( n-- ) result += s;
return result;
}
int main()
{
cout << 3 * string( "This will be printed repeatedly!\n" );
}
or
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <string>
usingnamespace std;
string operator *( unsignedint n, string s ) { return n ? ( n - 1 ) * s + s : ""; }
int main()
{
cout << 3 * string( "This will be printed repeatedly!\n" );
}
I guess there's also
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <string>
usingnamespace std;
#define TIMES( n ) for ( int i = 1; i <= ( n ); i++ )
int main()
{
TIMES( 3 ) cout << "This will be printed repeatedly!\n";
}
If you want all output on one line just remove the \n from the string.