Getline - // trailing '\n' and the following ignore should...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <iomanip> #include <cstring> using namespace std; int main() { char first[25] ; char last[25] ; char full_entered[50] ; char full_computed[50] = "" ; char pause[10] ; cout << "Enter your first name: " ; cin >> first ; //cin.getline(first,'\n'); cout << "Enter your last name: " ; cin >> last ; // cin.getline(last,'\n'); cout << "Enter your full name: " ; // Consume the remaining characters in the line. // The previous cin >> last will leave the last '\n' // in the input stream - we need to remove it. // Note that if we replace "cin >> last" with the commented // out cin.getline(last,'\n') then that getline removes the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // trailing '\n' and the following ignore should be reomved. cin.ignore(1000,'\n'); cin.getline(full_entered, 50, '\n'); strcat(full_computed, first) ; strcat(full_computed, &quot; &quot;) ; strcat(full_computed, last) ; if (strcmp(full_computed, full_entered)) { cout &lt;&lt; &quot;The strings are not the same.&quot; &lt;&lt; endl ; } else { cout &lt;&lt; &quot;The strings are the same.&quot; &lt;&lt; endl ; } cout &lt;&lt; &quot;Your full name as entered is: &quot; &lt;&lt; full_entered &lt;&lt; endl ; cout &lt;&lt; &quot;Your full name as computed is: &quot; &lt;&lt; full_computed &lt;&lt; endl ; }...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Ask a homework question - tutors are online