Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8114445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:08:51+00:00 2026-06-06T03:08:51+00:00

I wrote following function void validateUser(void) { string uName; string uPassword; char c; map

  • 0

I wrote following function

 void validateUser(void)
 {
         string uName;
         string uPassword;
         char c;

         map <char*, char*> authMap;
         authMap["balaji"] = "balaji";
         authMap["rohan"] = "rohan";

         cout << "Please Enter your user name :";
         cin >> uName;
         cout << "Please Enter your password :";
        // initTermios(0);
         while((c = getchar()) != '\n')
         {
           uPassword.push_back(c);
         }
         cout << "YOU Entered :: "<<  uPassword <<std::endl;
}

When i executed the above function, i found that after entering user name i press enter key then control does not enter into while loop even if i did not entered any password string.
Ant solution to above ? Thanks in advace.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:08:54+00:00Added an answer on June 6, 2026 at 3:08 am

    The newline character entered as a result of entering the username is still in standard input, and it is this that is read next thus the loop terminating condition is immeditately false. You need to skip past the newline character, which can be achieved using ignore():

    cin.ignore();
    

    Suggest not mixing use of C and C++ IO functions (I am unsure of the exact rules how this interact but I prefer to avoid it):

    while (cin.get(c) && '\n' != c)
    {
        uPassword.push_back(c);
    }
    

    or just use std::getline():

    getline(cin, uPassword);
    

    As mentioned in my comment, the map will be keyed by the address of the string literal, not the string content. Suggest using map<std::string, std::string> instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a managed C++ class that has the following function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)
I wrote a small tcp client using boost::asio, providing the following function: typedef boost::function<void(const
hi I was writing a BST and wrote following function for adding Child. void
I wrote the following function in haskell, as it will enumerate every integer: integers
I wrote the following: Object.prototype.length = function(){ var count = -1; for(var i in
I want to call the Sleep function on ASM. So I wrote the following:
I want to write the following procedure / function: procedure ShowSysPopup(aFile: string; x, y:
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I wrote the following function to split the given full path into directory, filename
i have the following function i wrote to create an XML file using Xerces

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.