Created
April 23, 2021 16:18
-
-
Save apocsantos/ed26835bdb634326ea9e3f6383d3fd84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include<string> | |
| /* run this program using the console pauser or add your own getch, system("pause") or input loop */ | |
| using namespace std; | |
| void convertion(string s); | |
| int main(int argc, char** argv) | |
| { | |
| string str; | |
| cout<<"Escreva uma frase sem espacos: "; | |
| getline(cin, str); | |
| int i; | |
| cout<<"Apresentada invertida: \n"; | |
| for(i = str.length() - 1; i >= 0; i--) //usando o string lengh, mas poderia usar conversão implicita | |
| { | |
| cout<<str[i]; | |
| } | |
| string s = str; | |
| cout<<"\n"; | |
| implicitconvertion(str); | |
| return 0; | |
| } | |
| void convertion(string s) | |
| { | |
| cout <<"O mesmo mas com conversão de string para char array: \n"; | |
| int i=0; | |
| string str = s; | |
| char cstr[str.size() + 1]; | |
| copy(str.begin(), str.end(), cstr); | |
| cstr[str.size()] = '\0'; | |
| cout<<"Apresentada invertida: \n"; | |
| for (i = sizeof(cstr); i >=0; i--) | |
| { | |
| cout << cstr[i]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment