C++ Strings Part II
If you didn't read the first part, you can find it here.getline: may input spaces, as before.
e.g., getline(cin,s1) would assign “Navid Plus” to s1 in the "Navid Plus" example.
Example :
#include <iostream>// Coded by https://NavidPlus.blogspot.com#include <string>
#include<cstdlib> using namespace std; int main ( ) { string backString; cout << "What ever your going to write here, I will reverse it. " <<endl; getline (cin,backString); int theIndex = backString.length()-1; while ( theIndex >= 0) { cout << backString [theIndex] ; theIndex --; } cout << '\n' ; } |
No comments:
Post a Comment