CSV
-
Hi, You may use the separator parameter of a
std::ostream_iterator
, for instance:#include <iostream>
#include <iterator>
int main()
{
int vals[] = {1, 2, 3 ,4, 5};
std::copy_n(vals, 5, std::ostream_iterator<int>(std::cout, ",")); // =>1,2,3,4,5,
}cheers, AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
-
Hi, You may use the separator parameter of a
std::ostream_iterator
, for instance:#include <iostream>
#include <iterator>
int main()
{
int vals[] = {1, 2, 3 ,4, 5};
std::copy_n(vals, 5, std::ostream_iterator<int>(std::cout, ",")); // =>1,2,3,4,5,
}cheers, AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
Thanks for reply I use like this
CStdioFile test; CString itemtext="ABC,123"; CString itemtextm="1"; if (test.Open"C:\\\\Test.csv"CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate)) { test.Seek(0,CFile::end); test.WriteString("Name"); test.WriteString(","); test.WriteString("Class"); test.WriteString("\\n"); .WriteString(itemtext); test.WriteString(","); test.WriteString(itemtextm); test.WriteString("\\n"); test.Close(); }
Now problem is that itemtext comes with two column.I want to Write this(itemtext)in Single Column. Please help me
-
This has nothing to do with C++ but rather to the CSV format. If you google for the format specification (see here[^] for instance) you can see that: Fields with embedded commas must be enclosed within double-quote characters.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Thanks for reply I use like this
CStdioFile test; CString itemtext="ABC,123"; CString itemtextm="1"; if (test.Open"C:\\\\Test.csv"CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate)) { test.Seek(0,CFile::end); test.WriteString("Name"); test.WriteString(","); test.WriteString("Class"); test.WriteString("\\n"); .WriteString(itemtext); test.WriteString(","); test.WriteString(itemtextm); test.WriteString("\\n"); test.Close(); }
Now problem is that itemtext comes with two column.I want to Write this(itemtext)in Single Column. Please help me
With your code the output should be Name,Class\nABC,123,1\n. What output do you want with the same input?
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
-
This has nothing to do with C++ but rather to the CSV format. If you google for the format specification (see here[^] for instance) you can see that: Fields with embedded commas must be enclosed within double-quote characters.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
With your code the output should be Name,Class\nABC,123,1\n. What output do you want with the same input?
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
As far as I understood, he wants the string "ABC,123" be considered as one column in the CSV file. But this has nothing to do with C++, rather with the CSV syntax in which he has put double quotes around the field.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
As far as I understood, he wants the string "ABC,123" be considered as one column in the CSV file. But this has nothing to do with C++, rather with the CSV syntax in which he has put double quotes around the field.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++I am not very good at guess games :sigh:
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
-
I am not very good at guess games :sigh:
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
:-D Well, spending a lot of time in the programming forums improves that a lot...
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++