Entering an email...the correct way!

This is a discussion on Entering an email...the correct way! within the C++ Programming forums, part of the General Programming Boards category; Ahm, I take it back - getline() for strings appears to NOT be able to limit the string - I ...

  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
    21,749
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,893
    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

Page 2 of 2 FirstFirst 12
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, 02: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, 11:05 AM
  4. email in dos
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 01-13-2002, 11:10 AM
  5. Validating email addresses
    By RetroGamer1991 in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-30-2001, 10:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21