I am curious to know from the more experienced c++ programmers out there if there is a way to have a function read in files that have different formats. Example is one file has a template of house # then street name and the other file is the opposite, house name then street #. Again, just curious if there was some sleek code that I could add to my knowledge and tool box, instead of writing two different inFile functions.
Thank you all for your time.
EDIT
Here is some of the code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct WH
{
int inum;
string iname;
string warname;
int quant;
float whole;
float markup;
float retail;
};
void readinprime(WH);
ifstream inFile;
ofstream outFile;
int main()
{
WH ware[100];
//inFile.open("WLL1.txt", ios::in);
//inFile.open("WLL2.txt", ios::in);
//inFile.open("WLL3.txt", ios::in);
//inFile.open("WLL4.txt", ios::in);
return 0;
}
void readinprime(WH ware[])
{
int c;
for(c = 0; c < 100; c++)
{
inFile << ware.inum[c] << ware.iname[c];
}
}
So essentially the first file (WLL1.txt) has the format integer->string and then the next file (WLL2.txt) will have the format string->integer. My question is, is there another way to write the read in function where it can read in int then string & string then int without writing another function? I dont mind writing another function for every file format, but I was just curious if someone had some good tricks that I could add to my tool box. Again thank you for your time.