-1

I have a question, how to assign data into array? For example, I have a text file which consist of:

username1
password1
username2
password2
username3
password3
username4
password4

How to parse username2 and password 2 into array? I know I can use struct in this scenario but I am not allowed to use struct for my assignment.

Thanks.

Chuah Cheng Jun
  • 243
  • 1
  • 3
  • 17
  • 1
    This question has been asked many *many* times, how were these answers not useful to you? – Borgleader May 27 '15 at 14:01
  • possible duplicate of [Reading from text file until EOF repeats last line](http://stackoverflow.com/questions/21647/reading-from-text-file-until-eof-repeats-last-line) – Andreas DM May 27 '15 at 14:17

1 Answers1

0

Example:

#include <fstream>

ifstream infile;
infile.open("filename");

std::string a;
std::string b;
std::map<std::string, std::string>myMap;
std::string arr[10000];
int count = 0;
while (infile >> a >> b)
{
    arr[count++] = a; //username
    arr[count++] = b; //password
}
bhavesh
  • 1,343
  • 2
  • 14
  • 23