Question

i have a file named players.dat that has these names as their usernames and passwords //players.dat...

i have a file named players.dat that has these names as their usernames and passwords

//players.dat

mickeymouse clubhouse
goofy gawrsh
donaldduck phooey
pluto bloodhound
minniemouse polkadot

I want to read from this and input this into a vector, im new to vectors so can someone please help.

And dont use a sstream.

Homework Answers

Answer #1
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;

int main() {
    ifstream in("players.dat");
    if (in.is_open()) {
        string username, password;
        vector<string> users, passwords;
        while (in >> username >> password) {
            users.push_back(username);
            passwords.push_back(password);
        }
        cout << "User name vector" << endl;
        for (int i = 0; i < users.size(); ++i) {
            cout << users[i] << endl;
        }
        cout << "\nPasswords vector" << endl;
        for (int i = 0; i < passwords.size(); ++i) {
            cout << passwords[i] << endl;
        }
        in.close();
    } else {
        cout << "players.dat does not exists!" << endl;
    }
    return 0;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In matlab how to make it that i can be able to type in the file...
In matlab how to make it that i can be able to type in the file that I would like to test and to be able to test what algorithm i have. This is what i have so far. But I need help fixing the rest. Please help I need this asap. function FunctionAlgorithm() disp("Welcome to ___________ algorithm") filename = file = input('Type in the file to test: '); number = input('Type the number of the algorithm you want to...
How would I solve these python problems? A) File Display Download the file from here named...
How would I solve these python problems? A) File Display Download the file from here named numbers.txt . Write a program that displays all of the numbers in the file. numbers.txt contains 22 14 -99 AB B) Error Check Float Input When you want an int input you can check the input using the string isdigit() method. However, there is no comparable check for float. Write a program that asks the user to enter a float and uses a try-except...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code...
Instructions​: You will find a file named findingNemo.m and another named nemo.txt. The first contains code which will read in strings from nemo.txt, then call Lab08(string) on each line of nemo.txt. Your job is to write Lab08.m. The Lab08 function will take in a string as input and will return an integer n as output. The value of n will be the nth word in the input string, where n is the location of the substring 'Nemo'. Please note that...
Description The word bank system maintains all words in a text file named words.txt. Each line...
Description The word bank system maintains all words in a text file named words.txt. Each line in the text file stores a word while all words are kept in an ascending order. You may assume that the word length is less than 20. The system should support the following three functions: Word lookup: to check whether a given word exists in the word bank. Word insertion: to insert a new word into the word bank. No insertion should be made...
So, i have this code in python that i'm running. The input file is named input2.txt...
So, i have this code in python that i'm running. The input file is named input2.txt and looks like 1.8 4.5 1.1 2.1 9.8 7.6 11.32 3.2 0.5 6.5 The output2.txt is what i'm trying to achieve but when the code runs is comes up blank The output doc is created and the code doesn't error out. it should look like this Sample Program Output 70 - 510, [semester] [year] NAME: [put your name here] PROGRAMMING ASSIGN MENT #2 Enter...
write a non pure function (procedure) named drawstar that atkes no arguments and draws a 5...
write a non pure function (procedure) named drawstar that atkes no arguments and draws a 5 pointed star using python turtle graphics : the drawsar procedure should do the following : open a turtle dialogue box and have the user enter the length of each side. draw a five pointed star with each side length as entered by the user. (hint: the internal angle of each points is 36 degrees) to be honest, i really want to know how to...
3. A survey found 195 of 250 randomly selected Internet users have high-speed Internet access at...
3. A survey found 195 of 250 randomly selected Internet users have high-speed Internet access at home. Construct a 90% confidence interval for the proportion of all Internet users who have high-speed Internet access at home.  (Round to the nearest thousandth) 4. You want to estimate the proportion of adults who have a fear of snakes (ophidiophobia). What sample size should be obtained if you want the estimate to be within 3 percentage points with 95% confidence if you do not...
Coordination Compound Naming! I have 6 compounds to name. I named all 6, but please check...
Coordination Compound Naming! I have 6 compounds to name. I named all 6, but please check my answer and if wrong, please explain why and how to do it. Thank you so much! 1. [Pt(NH3)4Cl2]SO4  - tetraamminedichloroplatinum (IV) sulfate 2. K3[Mo(CN)6F2] - potassium hexacyanodifluoromolybdenate (V) 3. K[Co(EDTA)] - potassium ethylenediaminetetraacetate cobaltate(III) Note: For the cobalt oxidations state, I calculated it to be +3 because EDTA has a charge of -4 and and K is +1. So, it needs to be +3...
I have already written a MATLAB code to filter noise from a particular audio file however...
I have already written a MATLAB code to filter noise from a particular audio file however the resulted audio is not playing I use this code snippet: presult = audioplayer(fOut, fs); presult.play; the fout is fOut = filter(b, a, f); I do not know what i am doing wrong as the output playing is still the initial sound not thr noise filtered one. Please help deadline is due in hours. Thanks in advance
Imagine you're named an Economic Advisor to the president of a very poor and backward country...
Imagine you're named an Economic Advisor to the president of a very poor and backward country (Sandokistan).   The President asks your advice on where they should use their very limited resources so that they can help escape the poverty trap. Should they invest in existing, traditional tools (think tractors, computers, known manufacturing techniques) or should they invest in cutting edge research where they might become a market leader? Please explain why you selected the option you did.   Conversely, why didn't...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT