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 8374531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:56:36+00:00 2026-06-09T14:56:36+00:00

This is my partial code: if(action==auth) { myfile.open(account.txt); while(!myfile.eof()) { getline(myfile,sline); vector<string> y =

  • 0

This is my partial code:

if(action=="auth")
{


 myfile.open("account.txt");
    while(!myfile.eof())
    {
        getline(myfile,sline);

        vector<string> y = split(sline, ':');
    logincheck = "";
    logincheck = y[0] + ":" + y[3];

    if (sline==actionvalue)
    {
    sendClient = "login done#Successfully Login.";
    break;
    }
    else
    {
    sendClient = "fail login#Invalid username/password.";
    }

    y.clear();
    }
    myfile.close();

}

If i don’t have this

 logincheck = y[0] + ":" + y[3];

The code will not have any segmentation core dump error, but when I add that line, it will went totally wrong.

My account.txt is as followed:

admin:PeterSmite:hr:password
cktang:TangCK:normal:password

The split function:

std::vector<std::string> split(std::string const& str, std::string const& delimiters = "#") {
  std::vector<std::string> tokens;

  // Skip delimiters at beginning.
  string::size_type lastPos = str.find_first_not_of(delimiters, 0);
  // Find first "non-delimiter".
  string::size_type pos = str.find_first_of(delimiters, lastPos);

  while (string::npos != pos || string::npos != lastPos) {
    // Found a token, add it to the vector.
    tokens.push_back(str.substr(lastPos, pos - lastPos));
    // Skip delimiters.  Note the "not_of"
    lastPos = str.find_first_not_of(delimiters, pos);
    // Find next "non-delimiter"
    pos = str.find_first_of(delimiters, lastPos);
  }
  return tokens;
}



std::vector<std::string> split(std::string const& str, char const delimiter) {
  return split(str,std::string(1,delimiter));
}
  • 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-09T14:56:38+00:00Added an answer on June 9, 2026 at 2:56 pm

    You should do some basic input checking before you blithely assume that the vector contains at least 4 elements, otherwise y[3] will explode when you parse a line of input without three colons:

    if (y.size >= 4) {
       // Do login check
    } else {
       // Invalid input
    }
    

    I’d guess that you probably have a blank line in your input.

    Wrap the whole section of code that relies on reading a “a:b:c:d” line of input:

    if(action=="auth") {
      myfile.open("account.txt");
      while(getline(myfile,sline))
      {
        vector<string> y = split(sline, ':');
        if (y.size >= 4) {
          logincheck = "";
          logincheck = y[0] + ":" + y[3];
    
          if (sline==actionvalue) {
            sendClient = "login done#Successfully Login.";
            break;
          } else {
            sendClient = "fail login#Invalid username/password.";
          }
        }
      }
      myfile.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With this code: public partial class Form1 : Form { private static readonly int
Here is my code: partial void OnisApprovedChanging(bool value) { this.dateApproved = DateTime.Now; } 'dateApproved'
This is a simplified partial version of my code to demonstrate the issue: function
Hi I see following code: void UpdateMessage (string message) { Action action = ()
I have this code: BeginInvoke(new Action(() => tempNamesAndTexts.ForEach(Item => textBox1.AppendText(DateTime.Now + ===> + Item
I'm trying to learn Razor/MVC3 and having a bit of trouble with this partial
I have a program that looks something like this: public partial class It {
I have a page that is setup like this public partial class _Default :
Given this class public partial class Default : Page { private IRepository repo; ...
Consider this source: public partial class FormTest : Form { private Test test {

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.