Ex:
I open a .csv file with contents:
1 | John | 123
2 | Peter | 142
and I want to add a field after them, like:
1 | John | 123
2 | Peter | 142
3 | Edward | 154
First: you cannot compare c strings like on line 23. Use strcmp
Second: ID_length is too small. It leaves out the necessary terminating 0 hence it is ID_length+1 on line 17 and 22
If I input ID=2, it display "ID...." because in INFO column, "124" has "2" although the file has only one person. Can u help me with it? I have no idea.
void write_csv( const string& filename, const table_t& table )
{
ofstream f( filename.c_str() );
for (unsigned ri = 0; ri < table.size(); ri++)
{
f << table[ 0 ][ 0 ];
for (unsigned fi = 1; fi < table[ ri ].size(); fi++)
{
f << " | " << table[ ri ][ fi ];
}
f << "\n";
}
}
What's left is (2) -- if "Edward" is not in the table, then push_back() new record. Otherwise complain to the user.
Thank you, actually I'm doing a library manager program. That part is making a new account. Users input the ID, if the ID has already existed, the program would gave errors and exit, if not, ID would be written to a .csv file