Loading file with multiple lines
May 17, 2014 at 11:29pm UTC
I'm trying to load a file that look like this:
1 2
IP:123.123.123.123
Port:12345
I can't figure out how to load multiple lines. I tried using \n, but I can't get it to work. Is there a better way of doing it than I am right now? This is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
char message[100];
int messageCount = 0;
for (unsigned int i = 0; i < file.size(); ++i) {
message[i] = file[i];
}
string coords = message;
istringstream ss(coords);
string token;
vector<string> fileLines;
while (getline(ss, token, '\n' )) {
fileLines.push_back(token);
cout << endl << "Tokens: " << endl;
cout << token << endl;
}
for (unsigned int i = 0; i < fileLines.size(); i++) {
messageCount = 0;
coords = fileLines[i];
istringstream ss(coords);
while (getline(ss, token, ':' )) {
if (messageCount == 1) {
loadIP = token.c_str();
}
else if (messageCount == 3) {
loadPort = atoi(token.c_str());
}
messageCount++;
}
}
May 18, 2014 at 4:43am UTC
Figured it out, but config doesn't look as nice as before. I looks like this now
1 2
IP:123.123.123.123:
Port:12345:
Topic archived. No new replies allowed.