如何在C++中多次打印字符

gih*_*ith -6 c++ loops

2*

4**

6***

需要输出上面的模式下面给出的代码我已经尝试过

#include <iostream>
#include<string>

using namespace std;

int main (){
string star = "*";
int a=2;
while(a<=6){
    cout<<a<<star*(a/2)<<endl;
    a+=2;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)

Art*_*sky 5

#include <iostream>
#include<string>

int main () {
    for(auto i=1;i<=3;i++)
    {
        std::cout << i*2 << std::string(i,'*') << '\n';
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)