我用下面的代码,生成了cvs文件。想请教下面问题。
1.怎么生成文件的同时,在文件里面写入数据?(我是新手,请指教的详细一点,在网上查了许多都没搞明白,拜托了)
2.CVS文件,是用Excel打开的,怎样把文件里面的数据放入同一排的不同网格里?
MakeFile.h文件:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {savefile();}
MakeFile.cpp文件
void MakeFile::savefile()
{
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "cvs files (*.cvs)|*.cvs";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
System::IO::Stream^ mystream;
if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )
{
if ( (mystream = saveFileDialog1->OpenFile()) != nullptr )
{
mystream->Close();
}
}
------解决方案--------------------------------------------------------
用StreamWriter吧,直接把内容写入到文件中
------解决方案--------------------------------------------------------
- C# code
using System.IO; StreamWriter sw = new StreamWriter("tst.cvs", true); sw.WriteLine("hello world"); sw.Close();