string
1.string函数
1 2 3 4 5 6
| s.append(str); s.find(str); s.erase(index, length); s.insert(index, str) s.substr(start, length)
|
2.output diamond name diamond
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <iostream>
using namespace std;
void nameDiamond(string str){ for(int i = 0; i < str.length(); ++i){ cout << str.substr(0, i + 1) << endl; }
for(int i = 0; i < str.size(); ++i){ str.replace(i, 1, " "); cout << str << endl; }
for(int i = 0; i < str.length(); ++i){ for(int j = 0; j <= i; ++j){ cout << " "; } cout << str.substr(i + 1) << endl; } }
int main(){ string str("adomais"); nameDiamond(str); return 0; }
|