How to repeat a CHAR repeat STD :: string

xiaoxiao2021-03-05  26

If you want to get a string similar to "***********" using std :: string, you can use a loop: string S; for (int N = 0; n <10; n ) {s = S '*';} But it doesn't seem to be so simple and "professional", there is a better way: string s; s.resize (10, '*');

String's resize () can expand (or reduced) S to a certain length and fill the newly extended space with the specified character. It can also be used: s = "abc"; s.Resize (5, "*"); s Value is "abc **"

However, repeating a sub-string several times (such as "* & * & * & * & * &", ie repeat "* &" 5 times) I haven't found a good method yet, I can only use the loop :)

转载请注明原文地址:https://www.9cbs.com/read-35420.html

New Post(0)