Thread: Entering an email...the correct way!

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ahm, I take it back - getline() for strings appears to NOT be able to limit the string - I don't quite know how you'd do that.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Sep 2007
    Posts
    37
    matsp, on the link you gave, it says...
    Code:
     string s;
     getline( cin, s );
     cout << "You entered " << s << endl;
    But I thought string wasn't a keyword? O_O
    And Im afraid I did not understand your solutions to the problem (pheres and matsp)...

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    That reference implicitly assumes that the std namespace is in use, so string is actually std::string, just as getline, cin, cout and endl are actually std::getline, std::cin, std::cout and std::endl respectively. Either way they are not keywords, but names from the std namespace.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by matsp View Post
    Ahm, I take it back - getline() for strings appears to NOT be able to limit the string - I don't quite know how you'd do that.
    Basically, by implementing your own getline using low-level character input and string's push_back. Not pleasant, but since getline() is lacking, pretty much unavoidable.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #20
    Registered User
    Join Date
    Sep 2007
    Posts
    37
    Thanks for that one o.o
    I wonder how I can do away with the recursion here, though...?

  6. #21
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Instead of

    Code:
    get_email()
    {
      get input;
    
      if(error)
      {
         get_email();   // <- recursion. You are calling A from inside A again and again, as long
                               // as invalid formats are entered
      }
    
    }
    as you are doing now, do

    Code:
    bool success = false;
    
    do
    {
      get_email();
      if(error)
      {
         success = false;
      }
       else
       {
          success = true;
       }
    }
    while(! success)     // <- now call A in a loop, till a valid address is gotten

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux for GNU/Linux is not correct?
    By password636 in forum Linux Programming
    Replies: 8
    Last Post: 03-31-2009, 08:30 PM
  2. Storing names and email address.
    By arya6000 in forum C Programming
    Replies: 15
    Last Post: 11-19-2008, 03:47 AM
  3. Spam Filters. ISP based email is dying.
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 03-05-2008, 12:05 PM
  4. email in dos
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 01-13-2002, 12:10 PM
  5. Validating email addresses
    By RetroGamer1991 in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-30-2001, 11:33 PM