ignore funtiction?

L

Luis

Please help, this is due at 11:59 PM tonite. Thanks



Write a program that reads a person's name from the keyboard in the format
First Middle Last. It should then (1) print each of the names on a separate
line and (2) print the person's initials on the fourth line. Assume that
each person has exactly 3 names, that the first name begins in the first
position on a line (there are no leading blanks) and that the names are
separated from each other by a single blank.

Do not use arrays in this assignment.



SO far i gigured out only how to print out the initials, but i can't figure
out how to get each part of a name as a seperate string. Can any one help me
out? here is my source so far

#include <iostream>
#include <string>


using namespace std;

int main ()
{

char m;
char l;
char f;



cin>>f;
cin.ignore(100,' ');
cin>>m;
cin.ignore(100,' ');
cin>>l;

cout<<f<<m<<l<<endl;



return 0;
}
 
V

Victor Bazarov

Luis said:
Please help, this is due at 11:59 PM tonite. Thanks



Write a program that reads a person's name from the keyboard in the format
First Middle Last. It should then (1) print each of the names on a separate
line and (2) print the person's initials on the fourth line. Assume that
each person has exactly 3 names, that the first name begins in the first
position on a line (there are no leading blanks) and that the names are
separated from each other by a single blank.

Do not use arrays in this assignment.



SO far i gigured out only how to print out the initials, but i can't figure
out how to get each part of a name as a seperate string. Can any one help me
out? here is my source so far

#include <iostream>
#include <string>


using namespace std;

int main ()
{

char m;
char l;
char f;

Declare them as 'string'.
cin>>f;
cin.ignore(100,' ');
cin>>m;
cin.ignore(100,' ');
cin>>l;

Drop the 'ignore's.
cout<<f<<m<<l<<endl;

To output each of them on a separate line you need a line
separator between them, don't you?

Now, regarding the initials, what are they? Each initial
is the very first character of each name, right? So, output
the initials by outputting the very first character in each
string.
 
A

Andre Kostur

Luis said:
Please help, this is due at 11:59 PM tonite. Thanks



Write a program that reads a person's name from the keyboard in the
format First Middle Last. It should then (1) print each of the names
on a separate line and (2) print the person's initials on the fourth
line. Assume that each person has exactly 3 names, that the first name
begins in the first position on a line (there are no leading blanks)
and that the names are separated from each other by a single blank.

Do not use arrays in this assignment.



SO far i gigured out only how to print out the initials, but i can't
figure out how to get each part of a name as a seperate string. Can
any one help me out? here is my source so far

#include <iostream>
#include <string>


using namespace std;

int main ()
{

char m;
char l;
char f;



cin>>f;
cin.ignore(100,' ');
cin>>m;
cin.ignore(100,' ');
cin>>l;

cout<<f<<m<<l<<endl;



return 0;
}

Well..... first thing to note is that you're reading into variables of
type 'char'. char can only hold one character. Look up a standard type
named "std::string".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top