老铁们,大家好,相信还有很多朋友对于createfile函数和createfile函数详解的相关问题不太懂,没关系,今天就由我来为大家分享分享createfile函数以及createfile函数详解的问题,文章篇幅可能偏长,希望可以帮助到大家,下面一起来看看吧!
c# 编程CreateFile函数
你找的是c++里的创建文件的函数,在c#里应该是用下面的
--------------------------------------------------------------------------------------
File类
提供用于创建、复制、删除、移动和打开文件的静态方法,并协助创建FileStream对象。
继承层次结构
System.Object
System.IO.File
命名空间:System.IO
程序集:mscorlib(在mscorlib.dll中)
语法
C#
publicstaticclassFile
File类型公开以下成员。
公共方法静态成员Create(String)在指定路径中创建或覆盖文件。
公共方法静态成员Create(String,Int32)创建或覆盖指定的文件。
公共方法静态成员Create(String,Int32,FileOptions)创建或覆盖指定的文件,并指定缓冲区大小和一个描述如何创建或覆盖该文件的FileOptions值。
公共方法静态成员Create(String,Int32,FileOptions,FileSecurity)创建或覆盖具有指定的缓冲区大小、文件选项和文件安全性的指定文件。
下面的示例在指定路径中创建一个文件,将一些信息写入该文件,再从文件中读取。
usingSystem;
usingSystem.IO;
usingSystem.Text;
classTest
{
publicstaticvoidMain()
{
stringpath=@"c:\temp\MyTest.txt";
try
{
//Deletethefileifitexists.
if(File.Exists(path))
{
//Notethatnolockisputonthe
//fileandthepossibilityexists
//thatanotherprocesscoulddo
//somethingwithitbetween
//thecallstoExistsandDelete.
File.Delete(path);
}
//Createthefile.
using(FileStreamfs=File.Create(path))
{
Byte[]info=newUTF8Encoding(true).GetBytes("Thisissometextinthefile.");
//Addsomeinformationtothefile.
fs.Write(info,0,info.Length);
}
//Openthestreamandreaditback.
using(StreamReadersr=File.OpenText(path))
{
strings="";
while((s=sr.ReadLine())!=null)
{
Console.WriteLine(s);
}
}
}
catch(ExceptionEx)
{
Console.WriteLine(Ex.ToString());
}
}
}
c语言createfile函数用法
你说的如果是自定义函数。就先写出来,比如
#include
voidcreate()
{
//这里写函数代码
}
intmain()
{
create();//在主函数里进行调用
}
关于CreateFile函数
不行的话你就强制写CreateFileA而不是CreateFile吧。
CreateFile有两个版本,CreateFileA和CreateFileW。
只写CreateFile的话它会根据工程的设置自动选择一个来用。
另外我赞成_T宏的方式,这也是让编译器自动选择一种字符串的表示方式来用
文章分享结束,createfile函数和createfile函数详解的答案你都知道了吗?欢迎再次光临本站哦!