[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I need help getting data from a file in c++ The file starts

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 1

File: Untitled.jpg (10KB, 224x89px) Image search: [Google]
Untitled.jpg
10KB, 224x89px
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.
Thread posts: 7
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.