Hello I am very new to programming and C++. I'm trying to make a program that checks if a string is a palindrome (a word that is the same backwards as it is forwards).
In order to do that I searched online about how to reverse a string and came across the reverse(string.begin(), string.end()) function from <bits/stdc++.h>.
I've made a function that can reverse the string written in the parameters and it works fine:
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
std::string reverseStr(std::string str) {
reverse(str.begin(), str.end());
return str;
}
int main() {
std::cout << reverseStr("word");
}
But when I want to assign the reversed string into a new variable "reversedStr":
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
std::string reverseStr(std::string str) {
std::string reversedStr;
reversedStr = reverse(str.begin(), str.end());
return reversedStr;
}
int main() {
std::cout << reverseStr("word");
}
Then when I try and compile it, it gives me this error.
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/basic_string.h:776:7: note: no known conversion for argument 1 from 'void' to 'std::initializer_list<char>'
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command g++ -g main.cpp" terminated with exit code: 1.
If you wouldn't mind explaining what is happening that would be great! Thank you!