COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
string_reverse.cpp File Reference
#include <iostream>
#include <string>
Include dependency graph for string_reverse.cpp:

Go to the source code of this file.

Functions

int main ()
 
string reverse (string s)
 

Function Documentation

◆ main()

int main ( void )

Definition at line 31 of file string_reverse.cpp.

32{
33 string s;
34 cin >> s;
35
36 cout << "String in reverse = " << reverse(s) << endl;
37
38
39 return 0;
40
41}
string reverse(string s)

References reverse().

Here is the call graph for this function:

◆ reverse()

string reverse ( string s)

Definition at line 21 of file string_reverse.cpp.

22{
23 if (s.length() < 2)
24 return s;
25 else
26 return s[s.length() - 1] + reverse(s.substr(0, s.length() - 1));
27 // string.substr(starting_index, length) usage
28}

References reverse().

Referenced by main(), and reverse().

Here is the call graph for this function:
Here is the caller graph for this function: