Thread: Converting fprint to cout

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    6

    Converting fprint to cout

    Checked the FAQ for a solution - no help.

    I'm using MS visual C++ 6.0. Teaching myself C++.
    Tried to convert a C program. Ran into a problem with a
    printf statement. Can't convert it to a cout.

    Thanks in advance for any suggestions. Here is the code:


    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    
    {
    	char ch, ans;
    	ch = 'Y';
    
       
    	cout <<"ROUTINE TO CONVERT A CHARACTER TO ITS ASCII VALUE";
        cout << endl <<endl <<endl;
    
    	while (ch == 'Y' || ch == 'y')
    
    	{
    		cout <<"Enter a character   :";
    		cin >> ans;
    		cout << endl;
    
    		
            printf("The ASCII value of %c is %d\n",ans,ans);
    
    
    		cout << endl  <<endl;
    	
    		ch = 'x';
    	    
    	while (ch != 'Y' && ch != 'y' && ch != 'N' && ch != 'n')
        
    	
    	{
    		cout << endl  <<endl;
    		cout <<"    ANOTHER  (Y/N  ?  :  ";
    		cin >> ch;
    	}
    
    	
    	}
    
    	
    
    	return 0;
    
    }
    [edit]Code tags added by Hammer.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You could;

    Code:
    cout << "The ASCII value of " << ans << " is " << (int)ans << endl;

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    6

    Wink

    Fordy,

    Thanks. Worked OK.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Spying" on cout
    By sirjis in forum C++ Programming
    Replies: 4
    Last Post: 11-06-2006, 05:00 PM
  2. cout to printf problems
    By hallo007 in forum C++ Programming
    Replies: 9
    Last Post: 09-27-2006, 10:22 AM
  3. c++ string input
    By R.Stiltskin in forum C++ Programming
    Replies: 4
    Last Post: 02-22-2003, 04:25 PM
  4. I'm REALLY confused. Why isn't cout or cin working here?
    By niudago in forum C++ Programming
    Replies: 8
    Last Post: 02-15-2003, 05:53 PM
  5. FAQ cout
    By evilmonkey in forum FAQ Board
    Replies: 1
    Last Post: 10-07-2001, 11:32 AM