RESOLVED:
Big thanks to
Richard MacCutchan and everyone else who contributed to the thread!
So, the problem was that I wanted to take values from a CSV file that is formatted something like this:
Fname1,Minitial1,LName1,Com1,(Desc1)
Fname2,Minitial2,LName2,Com2,(Desc2)
Fname3,Minitial3,LName3,Com3,(Desc3)
What I wanted to accomplish was take each token delimited by a comma and assign it to a temporary value. The reason why I wanted to do this was because I wanted to rearrange the input values in to a specific order as well as be able to output the same token multiple times. This is an example of the desired output:
LName1 Com1 Fname1 Minitial1 (Desc1) Fname1.LName1
LName2 Com2 Fname2 Minitial2 (Desc2) Fname2.LName2
LName3 Com3 Fname3 Minitial3 (Desc3) Fname3.LName3
As you can see, temporary tokens [0] - 4] are needed to be able to accomplish this. For my specific purpose, the tokens needed to be rearranged as:
outfile << szToken[2] << " ";
outfile << szToken[3] << " ";
outfile << szToken[0] << " ";
outfile << szToken[1] << " ";
outfile << szToken[4] << " ";
outfile << szToken[0] << ".";
outfile << szToken[2] << endl;
Here is the entire code:
#include iostream
#include fstream
#include string
using namespace std;
int main () {
string line;
ifstream infile ("infile.csv");
ofstream outfile ("outfile.txt");
if (infile.is_open())
{
while (getline(infile, line))
{
char* pszLine = new char[line.length() + 1];
strcpy(pszLine, line.c_str());
char* szToken[5];
szToken[0] = strtok(pszLine, ",");
for (int i = 1; i < 5; ++i)
{
szToken[i] = strtok(NULL, ",");
}
outfile << szToken[2] << " ";
outfile << szToken[3] << " ";
outfile << szToken[0] << " ";
outfile << szToken[1] << " ";
outfile << szToken[4] << " ";
outfile << szToken[0] << ".";
outfile << szToken[2] << endl;
delete []pszLine;
}
}
}
This will actually end up being used to produce VB scripts.
Thanks again to everyone, and I hope the next time I post here, it's helping someone like you guys helped me!