This looks a bit over-engineered in the sense that a 2D array (vector of vectors) isn't really necessary. All that is needed is a vector to hold the headings, and a separate vector to hold the current line.
I would break this into separate functions, one to get each line of data values, and another to output a single line (either the headings or the data) to the file. The latter is where I would add the quotation marks.
A couple of other comments. Firstly there is no
main()
function, so this isn't a valid C++ program. Change
int create()
to
int main()
.
Everything here is ordinary text, so there's no need to open the file in binary mode. It would be sufficient to simply put
|
ofstream myfile(writingFile.c_str());
|
which declares and opens the stream for output, in text mode.
The newline character can simply be specified as '\n' rather than as a pair of values. I realise that Windows does use the CRLF pair for line endings, but in text mode the translation is done automatically.
At line line 79 you have
cin.sync();
which is not a reliable way to do what is needed. The behaviour of cin.sync() is implementation-defined, which means the program may seem to work, but if you try to use a different compiler it may not. A better approach to clearing the input buffer here is something like
cin.ignore(1000, '\n');
which will ignore up to 1000 character, or until the newline character is found. Its purpose here is to get rid of the unwanted newline which remains in the input buffer after a previous
cin >>
.
Use of
system("cls");
is not recommended. For one thing it is slow, but the use of system() in general can create a security hole, so it's best to avoid the habit.
I had a few other comments, but that will suffice for now I think.
Edit As for your question about
vector iterators = *jt blah blah. |
In some ways an iterator can be thought of as being a bit like a
pointer. However they are also one of the building blocks used by the different containers such as std::list or std::set in the C++ standard library. One of the good things about the iterator is that once you know how to use it with one type of container, such as std::vector, it becomes relatively straightforward to reuse that knowledge with the other container types.
http://www.cplusplus.com/doc/tutorial/pointers/
http://www.cplusplus.com/reference/stl/