Advertisement
TheWhiteFang

Tutorial 4 Section A (d) [convert string to ASCII]

Dec 16th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. //http://pastebin.com/u/TheWhiteFang
  2. //Tutorial 4 Section A (d) [convert string to ASCII]
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. void convertToASCII(string letter)
  10. {
  11.     for (int i = 0; i < letter.length(); i++)
  12.     {
  13.         char x = letter.at(i);
  14.         cout << letter.at(i) << " = ";
  15.         cout << int(x) << endl;
  16.     }
  17. }
  18.  
  19. int main(){
  20.  
  21.         string name;
  22.        
  23.  
  24.         cout << "Please enter a string:\n";
  25.         getline(cin, name);
  26.     convertToASCII(name);
  27.         cout << endl;
  28.  
  29.  
  30.         cout <<"Your entered string is: "<< name <<" and the length is "<< name.length() << endl <<endl;
  31.  
  32.         return 0;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement