How to Convert Vector of int into String? Last Updated : 03 Dec, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, there are numerous cases where a vector of integers is needs to be converted into a string. In this article, we will learn the different methods to convert the vector of int into string in C++.The simplest method to convert the vector of int into string is by creating a stringstream and adding each integer to it one by one in the desired format. Let’s take a look at an example: C++ #include <bits/stdc++.h> using namespace std; int main() { vector<int> v = {1, 2, 3, 4, 5}; stringstream ss; // Insert every element of vector into stream for (int i : v) ss << i; // converts stream contents into a string cout << ss.str(); return 0; } Output12345Explanation: In the above code, first we create a stringstream object and inserts each element of the vector v into the stream using a loop. After all elements are added to the stream, the stringstream str() function is called to convert the contents of the stream into a single string.There are also some other methods in C++ to convert vector of int into string. Some of them are as follows:Table of ContentUsing accumulate()Using transform()Manually using LoopUsing accumulate()The accumulate() method can be used to convert a vector of integers into a string by applying to_string() to each element and appending the result to a string variable s. C++ #include <bits/stdc++.h> using namespace std; int main() { vector<int> v = {1, 2, 3, 4, 5}; // Convert vector of integer to string string s = accumulate(v.begin(), v.end(), string(), [](const string &a, int b) { return a + to_string(b); }); cout << s << endl; return 0; } Output12345 Using transform()The transform() method can also be used to convert the vector of integer to string by transforming every element to its character equivalent by adding with '0' and then appended them to resultant string using back_inserter(). C++ #include <bits/stdc++.h> using namespace std; int main() { vector<int> v = {1, 2, 3, 4, 5}; string s; // Convert vector of integer to string transform(v.begin(), v.end(), back_inserter(s), [](int i) { return i + '0'; }); cout << s; return 0; } Output12345Manually using LoopTo convert a vector of integers into a string iterate through each element of the vector, convert it to a string using their ASCII values and add it to the end of the string. C++ #include <bits/stdc++.h> using namespace std; int main() { vector<int> v = {1, 2, 3, 4, 5}; string s; // Convert vector of int to string for (auto i : v) { char c = i + '0'; s += c; } cout << s; return 0; } Output12345 Comment More infoAdvertise with us Next Article Vector of Strings in C++ K kartik Improve Article Tags : C++ STL cpp-strings-library cpp-algorithm-library Practice Tags : CPPSTL Similar Reads Convert String to int in C++ In C++, both string and int are not in the same object hierarchy, we cannot perform implicit or explicit type casting as we can do in case of double to int or float to int conversion. There are 6 significant methods to convert strings to numbers in C++ as follows:1. String to int Conversion Using st 6 min read Vector of Strings in C++ In C++, a vector of strings is a std::vector container that stores multiple strings. It is useful when you need to store a collection of string data in a single container and refer to them quickly. In this article, we will learn about the vector of strings and how to create and use it in C++.Table o 3 min read C++ Program to Convert String to Integer Given a string of digits, the task is to convert the string to an integer. Examples: Input : str = "12345" Output : 12345 Input : str = "876538"; Output : 876538 Input : str = "0028"; Output : 28 CPP // C++ program to convert String into Integer #include <bits/stdc++.h> using namespace std; // 1 min read Converting Number to String in C++ In C++, converting integers to strings or converting numbers to strings or vice-versa is actually a big paradigm shift in itself. In general or more specifically in competitive programming there are many instances where we need to convert a number to a string or string to a number. Let's look at som 4 min read Copy File To Vector in C++ STL Prerequisite:Â Vectors in C++ STLFile Handling in C++ The C++ Standard Template Library (STL) provides several useful container classes that can be used to store and manipulate data. One of the most commonly used container classes is the vector. In this article, we will discuss how to copy the conte 2 min read List of Vectors in C++ STL In C++, the list of vector refers to the list container in which each element is a vector. In this article, we will learn about the list of vectors in C++.Letâs take a look at an example:C++#include <bits/stdc++.h> using namespace std; int main() { list<vector<int>> l = {{1, 3}, {2 3 min read Like