Question: Rewrite Listing 4.4, using the C++ string class instead of char arrays. Here is some sample output for Listing 4.4: Enter your name: Dirk Hammernose

Rewrite Listing 4.4, using the C++ string class instead of char arrays.

Listing 4.4 instr2.cpp // instr2.cpp #include int main() { } reading more

Here is some sample output for Listing 4.4:
Enter your name:
Dirk Hammernose
Enter your favorite dessert:
Radish Torte
I have some delicious Radish Torte for you, Dirk Hammernose. The program now reads complete names and delivers the user his just desserts! The getline() function conveniently gets a line at a time. It reads input through the newline character marking the end of the line, but it doesn’t save the newline character. Instead, it replaces it with a null character when storing the string (see Figure 4.5).

than one word with getline using namespace std; const int Arsize =

Listing 4.4 instr2.cpp // instr2.cpp #include int main() { } reading more than one word with getline using namespace std; const int Arsize = 20; char name [Arsize]; char dessert [Arsize]; cout

Step by Step Solution

3.24 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The following is a C code that uses string class instead of ch... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction Java Program Questions!