0

The idea is to read a vectot using a function template and reverse its order then compare it to check if equal

Im having problem asigning the new reversed vectors to a new vector and compare it to original one. Also there is function call error. How can i correct this https://code.sololearn.com/c70U50f9ER3w/?ref=app

11th Nov 2021, 1:11 PM
Reynolds Onyango
Reynolds Onyango - avatar
1 Respuesta
+ 1
#include <iostream> #include <vector> #include <algorithm> #include <sstream> using namespace std; template<typename T> string str(T begin, T end); int main(){ vector<int> vec = {1, 7, 3, 8, 1}; string vec_str = str(vec.begin(), vec.end()); cout << "Values of vector: " << vec_str << endl; reverse(vec.begin(), vec.end()); string vec_rev = str(vec.begin(), vec.end()); cout << "The reverse of the number is: " << vec_rev << endl; bool p_result = vec_str==vec_rev; if (p_result) cout << "The number is a palindrome."; else cout << "The number is not a palindrome."; } template<typename T> string str(T begin, T end) { stringstream ss; for (; begin != end; begin++) ss << *begin; return ss.str(); } https://code.sololearn.com/c67gMjNTKeNH
25th Nov 2021, 3:27 PM
SoloProg
SoloProg - avatar