EDIT::
Here is a literal example of what I need. There will be a CSV file that is formatted like the following:
FName,MInitial,LName,Description,Comment
FName,MInitial,LName,Description,Comment
FName,MInitial,LName,Description,Comment
FName,MInitial,LName,Description,Comment
I need to be able to take those pieces and make something like this:
>> LName >> "." >> FName >> LName >> Comment >> FName >> MInitial >> Description >> endl;
>> LName >> "." >> FName >> LName >> Comment >> FName >> MInitial >> Description >> endl;
>> LName >> "." >> FName >> LName >> Comment >> FName >> MInitial >> Description >> endl;
>> LName >> "." >> FName >> LName >> Comment >> FName >> MInitial >> Description >> endl;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <string>
#include <vector>
#include <functional>
#include <iostream>
using namespace std;
void split(const string& s, char c,
vector<string>& v) {
string::size_type i = 0;
string::size_type j = s.find(c);
while (j != string::npos) {
v.push_back(s.substr(i, j-i));
i = ++j;
j = s.find(c, j);
if (j == string::npos)
v.push_back(s.substr(i, s.length( )));
}
}
int main( ) {
vector<string> v;
string s = "Account Name|Address 1|Address 2|City";
split(s, '|', v);
for (int i = 0; i < v.size( ); ++i) {
cout << v[i] << endl;
}
getchar();
}
|
http://www.blog.highub.com/c-plus-plus/c-parse-split-delimited-string/
This code reads through the input and breaks down the string using the delimiter "|".
What I want to do is be able to assign the pieces that it breaks down to temporary strings so I can rearrange them like so:
sample input
val1,val2,val3,val4,val5
val1,val2,val3,val4,val5
val1,val2,val3,val4,val5
val1,val2,val3,val4,val5
sampe output
val3,val4,val5,val1,val2
val3,val4,val5,val1,val2
val3,val4,val5,val1,val2
val3,val4,val5,val1,val2
So, again, what I want it to do is break down the string by reading the data where "val1" would be, assigning that to "temp str1," then "val2" to "tempstr2," 3 and so on until it completes val5. Then it does something like
outputfile >> str3 >> str4 >> str5 >> str1 >> str2 >> endl;
and just loop until doc!=good or something.
Any ideas?