I need help getting data from a file in c++
The file starts with the number of lines below, each containing two words and two integers.
I need to get the words into separate strings and the integers into separate ints, but I don't know how to manage that with the pipes. These values are going to be stored into objects which will be in a linked list so looping is okay
Any clue how to due this guys? I'd know how to handle it if there was only one pipe...
>>201938
man strtok
>>201938
http://stackoverflow.com/a/236803 ?
How would you handle it with one pipe?
>>202045
I know you can get it in a buffer char array, use a function to get an int for the pipe's location, and make string objects with a substring I guess... Doesn't seem like the cleanest way.
I can't use std library containers, so I don't know if I can use sstream, but I can use things like fstream, thankfully.
Is there a way to get file input with a delimiter the way shown in that link?
>>202014
that's actually really smart
>>202045
#include <fstream>
#include <string>
using std::string;
using std::fstream;
using std::stoi;
using std::getline;
int main(){
fstream file("shit.txt");
string s;
getline(file, s);
int lines = stoi(s);
while(file.good() && lines>0){
string word[2];
int num[2];
getline(file, word[0], '|');
getline(file, word[1], '|');
getline(file, s, '|');
num[0] = stoi(s);
getline(file, s, '|');
num[1] = stoi(s);
getline(file, s);//discard \n\r
lines--;
//do shit with word and num
}
file.close();
}
>>202427
I don't know exactly how that worked but it did. getline() and file stream in general perplex me. Thanks anon.