reading in .dat files

I need to read in two .dat files

contents of file 1
graham crackers; 2 squares 59
milk chocolate; 1 bar 235
cheese, swiss; 1 oz 108
marshmallows; 1 cup 159
i need to read in the first part as a string until the ";"

(string; double string double)

then the next file is a little different

contents of file 2
S'mores
2
4 squares graham crackers
1 bar milk chocolate
2 large marshmallows

(string w/ spaces
double
double string string w/ spaces)

how do you read the first 2 lines differently from the rest

would an array of structs work here?

then once they're read in i need to compare them to check if the ingredients needed for file 2 are in file 1
how do you read the first 2 lines differently from the rest


What exactly do you mean?
If your goal is to read them differently, why don't u just do so?
You could for example write an algorithm that applies only for the first two reads of the file.

You also don't have to process the input of the file, as soon as you get it.
You can for example read the entire file, store it in a string, and then process it.

i need to read in the first part as a string until the ";"


There you have it!
For example, define an array[size_us], use member 'seekg(x)' in a loop.
this is the code i have


#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>
#include <vector>
#include "vectorUtils.h"


using namespace std;


// Compute the number of calories in one serving of a recipe
void computeCalories (const char* nutrientFileName, const char* recipeFileName);



int main (int argc, char** argv)
{
if (argc != 3)
{
cerr << "Usage: " << argv[0] << " nutrientFile recipeFile" << endl;
return -1;
}

computeCalories (argv[1], argv[2]);
return 0;
}




// Compute the number of calories in one serving of a recipe
void computeCalories (const char* nutrientFileName, const char* recipeFileName)
{

//open first file/ read

//open 2nd file/ read

//compare two data sets

//loop through ingredients (inside recipes)

//look for corresponding ingredients in nutrients

//if found, add calories found times amount

//if not found, set all flag to false/no

//divide total calories by serving size
//print recipe name




}
Topic archived. No new replies allowed.