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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:53:20+00:00 2026-05-20T14:53:20+00:00

I am a newbie in C++. I am doing a C++ sign up form

  • 0

I am a newbie in C++. I am doing a C++ sign up form where I keep all the user datas in a text file named user.txt with formats like

name|password|address|postal|phone

Each user record will occupy one line.

So my first question how can I do this nicely in C++

As for the reading part, my main problem is how to separate the data by splitting “|” then put the records in a user array. So when I do a login function I can loop through the array to match users.

My current code for reading is

string User::readUser(){
    ifstream fin("user.txt");
    string line;
    while(getline(line,fin)){
        string name, password, address; int postal, phone;//put the records into a 2 dimention array
    }
    //return array
}
  • 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-05-20T14:53:21+00:00Added an answer on May 20, 2026 at 2:53 pm

    Check out this answer.

    In your case, the fields will be appended to the vector<string> in order, so you can access them directly from it. First position would correspond to the name, second to the password and so on.

    Here’s an example:

    // The elements should be in this order: name, password, address, postal, phone
    vector<string> v = split(line, '|');
    string name = v[0], password = v[1], address = v[2];
    

    As for your second question, you could create a structure or class that describes the user:

    struct User {
    
        // Using type string for all fields for convenience.
        string name, password, address, postal, phone;
    
        User(string n, string pw, string a, string p, string ph): name(n),
                                                                  password(pw),
                                                                  address(a),
                                                                  postal(p),
                                                                  phone(ph) {}
    
    };
    
    vector<User> uv;
    
    // ...
    
    // Split string, create user instance and append it to the user list
    vector<string> v = split(line, '|');
    uv.push_back(User(v[0], v[1], v[2], v[3], v[4]));
    

    To iterate over the User vector:

    for (int i = 0; i < uv.size(); ++i) {
        if (uv[i].name == "John") {
            // Process John...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

newbie doing Java homework here. I have one class named Album which contains the
I am a newbie with c# and window form I am doing a web
Yes all, another newbie question! I'm doing some maintenance work on an app I
Total newbie question, but I cant figure out what im doing wrong. I want
Newbie question... The objective: I intend to have an HTML text input field as
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I'm a newbie doing Objective-C, coming from Flex/Actionscript development. I have an iPhone app
I am learning c++, and I am having issues doing some newbie things. I
I'm a newbie using OpenMP with C++. I was doing a simple function, loading
i'm a newbie to iphone development. I'm doing a navigation-based app, and I'm having

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.