[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 923
  • Last Modified:

Write & Read to csv using C++.NET

I need the read the data from a csv file. When I read, I always got the whole row like below
Adata1,Adata2,Adata3
Bdata1,Bdata2,Bdata3
Cdata1,Cdata2,Cdata3

I wan to get only data1 from only row A, how to I remove the "," from each row so I can get each of them? I am using C++.Net Visual Stuido 2005.

2ndly I also need to write to a csv, how to I do that???
0
xiaoxin85
Asked:
xiaoxin85
1 Solution
 
DocSeltsamCommented:
Hi,
to seperate the values you might use a method like String.Split().

To get the thing done you should check out
    http://www.codeproject.com/cs/database/CsvReader.asp
and
    http://www.heikniemi.net/jhlib/

0
 
xiaoxin85Author Commented:
I want to create a csv and write something onto it, how do I do it???
0
 
xiaoxin85Author Commented:
I can create a csv and write onto it, the problem mi hav here is that whenever I open the file and write, it keep overwriting, I only want 2 add on instead of overwriting it.
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
Ashish PatelCommented:
Can you paste the code which you are using?
0
 
xiaoxin85Author Commented:
StreamWriter^ sw = gcnew StreamWriter("C:\\log.text");
sw->WriteLine(desFileName);
sw->Close();
0
 
Ashish PatelCommented:
Try using something like below.
StreamWriter SW;
    SW=File.AppendText("C:\\log.text");
    SW.WriteLine("This Line Is Appended");
    SW.Close();
0
 
Ashish PatelCommented:
very sorry, use the code below
StreamWriter^ sw = gcnew StreamWriter("C:\\log.text", true);
sw->WriteLine(desFileName);
sw->Close();
0
 
lucky_jamesCommented:
try creating file pointer ( put csv in name i.e. in place of "log.txt", write "log.csv")
and use '\t' for next column data and '\n' for next line.


your data is
Adata1,Adata2,Adata3
Bdata1,Bdata2,Bdata3
Cdata1,Cdata2,Cdata3

it should be written as
Adata1\tAdata2\tAdata3\nBdata1\tBdata2\tBdata3\nCdata1\tCdata2\tCdata3
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now