C++ 将文件文本分配到数组中
我有一个问题,如何将数据分配到数组中?例如,我有一个文本文件,其中包括:C++ 将文件文本分配到数组中,c++,arrays,file,C++,Arrays,File,我有一个问题,如何将数据分配到数组中?例如,我有一个文本文件,其中包括: username1 password1 username2 password2 username3 password3 username4 password4 如何将用户名2和密码2解析到数组中?我知道我可以在这种情况下使用struct,但我不允许在分配任务时使用struct 谢谢 示例: #include <fstream> ifstream infile; infile.open("filename")
username1
password1
username2
password2
username3
password3
username4
password4
如何将用户名2和密码2解析到数组中?我知道我可以在这种情况下使用struct,但我不允许在分配任务时使用struct
谢谢 示例:
#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
}
#包括
河流充填;
infile.open(“文件名”);
std::字符串a;
std::字符串b;
std::mapmyMap;
std::字符串arr[10000];
整数计数=0;
而(填充>>a>>b)
{
arr[count++]=a;//用户名
arr[count++]=b;//密码
}
这个问题已经被问了很多次了,这些答案怎么对你没用?可能是重复的A)你做作业给他带来了麻烦,B)他的任务是使用2个数组而不是地图。