c++ - Convert Vector<int> to String -
i want make program first input array of string, convert integer, , push vector.
the code :
string a; vector<long long int> c; cout << "enter message = "; cin >> a; cout << endl; cout << "converted message integer = "; (i=0;i<a.size();i++) { x=(int)a.at(i); cout << x << " "; //convert every element string integer c.push_back(x); }
the output :
enter message = haha converted message integer = 104 97 104 97
then write in file, , on next program want read back, , convert string, question how that? convert vector [104 97 104 97] string "haha".
i appreciate helps. thanks.
std::vector<int> data = {104, 97, 104, 97}; std::string actualword; char ch; (int = 0; < data.size(); i++) { ch = data[i]; actualword += ch; }
Comments
Post a Comment