天天看點

金海佳學C++primer 練習9.41vector(char)初始化 string**A people which is able to say everything becomes able to do everything.

vector(char)初始化 string

Practice 9.41

#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iterator>
#include <cmath>
#include <cstring>
#include <forward_list>
using namespace std;

void init_string(vector<char> & chvec, string & str) {
    for(auto i : chvec) {
        str += string(&i,);
    }
}
int main() {
    vector<char> chvec = {'j','i','n','h','a','i'};
    string res = "";
    init_string(chvec, res);
    cout << "Here's result: " << endl;  
    cout << res << endl;
    return ;
}
           

Output

Here's result: 
jinhai
           

**A people which is able to say everything becomes able to do everything.

**

繼續閱讀