Thread: How to Use Puts and Gets in C++

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    22

    How to Use Puts and Gets in C++

    I have already used puts and gets in C but now i am working on a program where i have asked a user to enter name for 5 times in a loop . Now want to print the names .. Can any body can help me how to print their full names using C++ ?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It is a bad idea to use gets() in C. So bad, that gets() has been removed from the latest C standard.

    To answer your question though
    Code:
    #include <string>
    #include <iostream>
    
    int main()
    {
         std::string s;
         std::cout << "Type in a line and I'll write it back at you ...";
         std::getline(std::cin, s);
         std::cout << s << '\n';
    }
    should get you started.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. puts/fputs
    By joybanerjee39 in forum C Programming
    Replies: 5
    Last Post: 10-25-2011, 02:49 PM
  2. puts array
    By meher81 in forum C Programming
    Replies: 21
    Last Post: 03-27-2010, 07:11 AM
  3. puts( );
    By xddxogm3 in forum C Programming
    Replies: 9
    Last Post: 03-28-2005, 12:42 PM
  4. Puts() or Printf() ?
    By hern in forum C Programming
    Replies: 5
    Last Post: 06-25-2003, 06:09 AM
  5. putchar vs puts
    By sballew in forum C Programming
    Replies: 7
    Last Post: 09-20-2001, 02:02 PM