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.
#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; }
Get Answers For Free
Most questions answered within 1 hours.