+ 2
Reverse and gets
I was trying to learn some string functions but i noticed that strrev() and gets() does not work in the SoloLearn playground. Does anyone know why?
3 ответов
+ 3
as you have started learning c++ you can use reverse function to reverse string in c++
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string s="reverseit";
reverse(s.begin(),s.end());
cout<<s;
return 0;
}
+ 2
Both functions are removed from C. You can still use fgets() as an alternative to gets(), but you have to implement yourself a function to reverse a string.
+ 1
strrev isn't included in the <strings.h> header for linux, best try to implement one such as the attached code. As for gets, its not recommended due to memory possible overwritten out of bounds.
https://code.sololearn.com/cO26g6EB47ma/?ref=app