#include <iostream>
#include <string>
int main()
{
char maj {};
char min {};
int num {};
int width {};
std::cin >> num >> width >> maj >> min;
std::string fill(width, min);
for (int i{ 0 }; i <= num; i++)
{
if (maj == 'n')
std::cout << i;
else
std::cout << maj;
if (i < num)
std::cout << fill;
}
return 0;
}
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
char major, minor;
int num, width;
cin >> num >> width >> major >> minor;
string line( num * (width+1) + 1, minor );
for ( int i = 0; i <= num; i++ ) line[i*(width+1)] = ( major == 'n' ? '0' + i % 10 : major );
cout << line << '\n';
}
fill is a std::string, sequence of chars, in the example it is created and initialised with '~~~'. The reason I used it was to take the embedded for loop out of your code as it doesn't change each time around the outer loop.