| #include "csvpp.h"␍␊ |
| ␍␊ |
| using namespace std;␍␊ |
| ␍␊ |
| using namespace csvpp;␍␊ |
| int main()␍␊ |
| {␍␊ |
| ␉RowReader tmp;␍␊ |
| ␉stringstream ss;␍␊ |
| ␉ss << "field1,field2,field3\r\n123,234,345\r\n999,000,111\r\n";␍␊ |
| ␉ss >> tmp;␍␊ |
| ␉rowiterator it;␍␊ |
| ␉int row = 0;␍␊ |
| ␉while(ss >> tmp)␍␊ |
| ␉{␍␊ |
| ␉␉switch (row)␍␊ |
| ␉␉{␍␊ |
| ␉␉␉case 0:␍␊ |
| ␉␉␉␉if (tmp["field1"] != "123")␍␊ |
| ␉␉␉␉{␍␊ |
| ␉␉␉␉␉cerr << "Failed at row " << row << endl;␍␊ |
| ␉␉␉␉␉return 1;␍␊ |
| ␉␉␉␉}␍␊ |
| ␉␉␉␉break;␍␊ |
| ␉␉␉case 1:␍␊ |
| ␉␉␉␉if (tmp["field1"] != "999")␍␊ |
| ␉␉␉␉{␍␊ |
| ␉␉␉␉␉cerr << "Failed at row " << row << endl;␍␊ |
| ␉␉␉␉␉return 1;␍␊ |
| ␉␉␉␉}␍␊ |
| ␉␉␉␉break;␍␊ |
| ␉␉}␍␊ |
| ␉}␍␊ |
| ␉␍␊ |
| ␉cout << "All tests ran successfully" << endl;␍␊ |
| RowReader tmp;␍␊ |
| stringstream ss;␍␊ |
| ss << "field1,field2,field3\r\n123,234,345\r\n999,000,111\r\n";␍␊ |
| ss >> tmp;␍␊ |
| rowiterator it;␍␊ |
| int row = 0;␍␊ |
| while(ss >> tmp)␍␊ |
| {␍␊ |
| switch (row)␍␊ |
| {␍␊ |
| case 0:␍␊ |
| if (tmp["field1"] != "123")␍␊ |
| {␍␊ |
| cout << tmp["field1"] << endl;␍␊ |
| cerr << "Failed at row " << row << endl;␍␊ |
| return 1;␍␊ |
| }␍␊ |
| break;␍␊ |
| case 1:␍␊ |
| if (tmp["field1"] != "999")␍␊ |
| {␍␊ |
| cerr << "Failed at row " << row << endl;␍␊ |
| return 1;␍␊ |
| }␍␊ |
| break;␍␊ |
| }␍␊ |
| row++;␍␊ |
| }␍␊ |
| ␍␊ |
| cout << "All tests ran successfully" << endl;␍␊ |
| return 0;␍␊ |
| } |
| }␍␊ |