I know in Java, you can use Arrays.toString() to return a String representation of an Array. Is there a method that serves a similar function in C++?
If you mean an array of characters, you can use something like what follows
std::vector arr {'a', 'b', 'c'};//the array
std::string str{arr.cbegin(), arr.cend()};//the generated string
Working example
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
int main(){
std::vector arr {'a', 'b', 'c'};
std::string str{arr.cbegin(), arr.cend()};
std::cout << str;
}
Live
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With