I want to know how to make a variable array with C++ dynamically.

Asked 2 years ago, Updated 2 years ago, 24 views

// The number of ifstream userInfoFile[number] increases or decreases.
// Is there a way to dynamically make that part into a variable arrangement...?  
// The number in the 'number' part is equal to userIDList.size(). 
// I thought I could use it as a variable 
// I'm asking because I'm curious about how to enter a constant statically or set it dynamically through a specific method.

void FileManage::loadUserInfoFile() {
 string tempID, tempEmail, tempAuth;
 ifstream userInfoFile[5]; // Make it a dynamic array

 try {
  for (size_t i = 0; i < userIDList.size(); i++) {
   openFileToRead(userInfoFile[i], (userIDList[i] + ".dat").c_str());
   while (userInfoFile[i] >> tempID >> tempEmail >> tempAuth) {
    insert email into userEmailList.push_back(tempEmail); // userEmailList vector
   }
  }
 }
 catch (string err) {
  cerr << err << endl;
  exit(EXIT_FAILURE);
 }
 for (size_t i = 0; i < userIDList.size(); i++) {
  userInfoFile[i].close();
 }
}

c++

2022-09-22 11:01

1 Answers

Write vector

vector userInfoFile


2022-09-22 11:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.