Hello, would like to ask about this problem im facing.
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <ios>
#include <string>
#include <string.h>
#include <vector>
#include <sstream>
#include <algorithm>
#define MAX_MSG 30
using namespace std;
vector<UserInit> ReadUsersInitial() {
fstream file ("Users_initial.txt");
FILE *file1 = fopen("Users_initial.txt", "r");
string tempFile;
if (file.good()) {
//blah blah
}
file.close();
fclose(file1);
int numOfElements =0;
char delim = ':';
numOfElements = count (tempFile, delim);
char* userArray [[B]numOfElements*2[/B]];
UserInit x;
vector<UserInit> UsersArray;
int counter = 0;
char* str = new char[tempFile.size() + 1];
copy(tempFile.begin(),tempFile.end(),str);
str[tempFile.size()] = '\0';
strip(str);
str = strtok (str, ":");
while (counter < numOfElements) {
userArray[counter] = str;
str = strtok (NULL, ":");
counter++;
}
}
delete[]str;
counter = 0;
int counter2 = 0;
while (counter < numOfEntry) {
x.SetType(atoi(userArray[counter2]));
x.SetUserID(atoi(userArray[counter2+1]));
x.SetUserName(userArray[counter2+2]);
x.SetUserClearance(atoi(userArray[counter2+3]));
counter2 += 4;
UsersArray.push_back(x);
counter++;
}
counter = 0;
counter2 = 0;
return UsersArray;
}
else
cout << "Error opening file, please try again.";
}
Input file
U:0:Alice:1:
U:1:Bob:2:
U:2:Carol:3:
U:3:Derek:4:
U:4:Eve:5:
the bolded part is where it lies. Basically my program is trying to read a set of values from a file, and allocating it to a vector. But somehow when i transferred my code to a WIndows environment from Linux, it doesnt work anymore. Any help is much appreicated