#include <iostream.h>
char first[ 20 ];
char middle[ 20 ];
char last[ 20 ];
main()
{
    cout << "What is your name ScumBag? ";
    cin >> first >> "\n" >> middle >> "\n" >> last;
    return 0;
}

remove the "\n"s -- that is only for cout. Not allowed to have literals (text in quotes) on the cin line.

Wow, that was right up there on the bone headed's list then. Thanx.

remove the "\n"s -- that is only for cout. Not allowed to have literals (text in quotes) on the cin line.

There is some syntax of cin that allowes us to ignore the \ns.. Isn't it?

>There is some syntax of cin that allowes us to ignore the \ns.. Isn't it?
You're probably thinking of the ws manipulator, but it discards all whitespace. If you want more control, you have to write your own manipulator:

class scan {
public:
  scan ( const char *init ): fmt ( init ) {}
  friend istream& operator>> ( istream& in, const scan& s )
  {
    while ( *s.fmt != '\0' && in && in.peek() == *s.fmt ) {
      in.get();
      ++s.fmt;
    }

    if ( *s.fmt != '\0' )
      in.setstate ( ios::failbit );

    return in;
  }
private:
  mutable const char *fmt;
};

And of course you can write custom manipulators so that they're used in exactly the same way as standard manipulators. This is only slightly more awkward than what the OP had before:

cin>> first >> scan ( "\n" ) >> middle >> scan ( "\n" ) >> last;

Of course, that's effectively a no-op because most formatted input discards leading whitespace by default. That's why removing those strings altogether still works as expected.

commented: Thanks for the insights, though i'm not a big fan or cin/cout it's good to learn more :) +1
#include <iostream.h>
char first[ 20 ];
char middle[ 20 ];
char last[ 20 ];
main()
{
    cout << "What is your name ScumBag? ";
    cin >> first >> "\n" >> middle >> "\n" >> last;
    return 0;
}

You should get rid of the newline in your input for starters also you may want to tell the user to put in their first, middle, last names because the way you have it the name will just fill up the allocated space you've given and go to the next without ever really designating a first, middle or last name just the size of the characters.

also dont use <iostream.h> , use <iostream>

#include <iostream.h>
char first[ 20 ];
char middle[ 20 ];
char last[ 20 ];
main()
{
    cout << "What is your name ScumBag? ";
    cin >> first >> "\n" >> middle >> "\n" >> last;
    return 0;
}

hi...

the problem is, you cant put escape sequences in input functions like cin>>, it should be like this..

cin>>first;
cout<<"\n";
cin>>middle;
cout<<"\n";
cin>>last;

there..you should use cout<< for escape sequences...

good luck!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.