Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CSV

CSV

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MsmVc
    wrote on last edited by
    #1

    Hi all How can i write Special character in CSV File(like ,)? Please help me

    A C 2 Replies Last reply
    0
    • M MsmVc

      Hi all How can i write Special character in CSV File(like ,)? Please help me

      A Offline
      A Offline
      Alain Rist
      wrote on last edited by
      #2

      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)

      M 1 Reply Last reply
      0
      • A Alain Rist

        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)

        M Offline
        M Offline
        MsmVc
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • M MsmVc

          Hi all How can i write Special character in CSV File(like ,)? Please help me

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          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++

          M 1 Reply Last reply
          0
          • M MsmVc

            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

            A Offline
            A Offline
            Alain Rist
            wrote on last edited by
            #5

            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)

            C 1 Reply Last reply
            0
            • C Cedric Moonen

              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++

              M Offline
              M Offline
              MsmVc
              wrote on last edited by
              #6

              Thanks Problem solved

              1 Reply Last reply
              0
              • A Alain Rist

                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)

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                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++

                A 1 Reply Last reply
                0
                • C Cedric Moonen

                  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++

                  A Offline
                  A Offline
                  Alain Rist
                  wrote on last edited by
                  #8

                  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)

                  C 1 Reply Last reply
                  0
                  • A Alain Rist

                    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)

                    C Offline
                    C Offline
                    Cedric Moonen
                    wrote on last edited by
                    #9

                    :-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++

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups