1

I am trying to post the following into a .csv file.

 stream<<"DesiredV"<<'\t'<<" Charge V "<<'\t'<<" Charge Current "<<'\t'<<"Float Voltage"<<'\r\n';

However, \t isn't tabbing over to the next column and \r\n isn't moving to the next row. I am opening the .csv with excel and using Qt.

moesef
  • 4,641
  • 16
  • 51
  • 68
  • Output formats through `std::ostream` aren't determined by file extension, they'll just write the plain, raw text. You might provide your own implementation to match particular formats (e.g. introducing particular stream manipulators to separate columns and records). BTW use `std::endl` instead of `"\r\n"`, it will do it right and portable for any OS. – πάντα ῥεῖ Feb 02 '13 at 00:53
  • Duplicate of the following question: http://stackoverflow.com/questions/1120140/csv-parser-in-c – Zamfir Kerlukson Feb 23 '13 at 09:57

1 Answers1

3

.csv files (Comma-separated values) use Comma , to seperate columns (http://en.wikipedia.org/wiki/Comma-separated_values)

So you should change all '\t' to ','

And you should use "\r\n" instead of '\r\n'. '\r\n' will be regarded as '\r' by compiler.

Kaifei
  • 1,568
  • 2
  • 13
  • 16
  • I see. What about the newline and carriage return issue I am having? – moesef Feb 02 '13 at 00:35
  • 1
    @moesef I think you should use `"\r\n"` instead of `'\r\n'`. `'\r\n'` will be regarded as `'\r'` by compiler, I think. – Kaifei Feb 02 '13 at 00:40
  • 1
    Besides that you can use \t but you should not name it csv anymore but change the extension to .tab which means tab separated would also work – Simon Wang Feb 02 '13 at 01:43