zoukankan      html  css  js  c++  java
  • Win32 API 的文件操作

    HANDLE hFile=CreateFile(_T("D:\\test.txt"),
            GENERIC_WRITE,FILE_SHARE_WRITE,NULL,
            CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
    //创建文件
    if (hFile == INVALID_HANDLE_VALUE) //判断是否创建成功

        ErrorHandler(
    "Could not open file.");   // process error 
        return 0;

    DWORD   dwBytesWritten, strSize; 
    //写入长度,准备写入的字符的长度
    TCHAR buff[]=_T("Hello 我的电脑");
    int length=sizeof(buff)/sizeof(TCHAR); //字符串长度
    char* dest=new char[];//初始化转换为char目标指针
    WideCharToMultiByte( CP_ACP, 0, buff,-1,
            dest, 
    sizeof(buff), NULL, NULL );//把宽字节转换为char也就是byte
    strSize=strlen(dest);//获得转换后字符的长度
    WriteFile(hFile, dest,strSize , 
        
    &dwBytesWritten, NULL); //写入文件
    CloseHandle(hFile); //关闭文件
  • 相关阅读:
    HackerRank
    HackerRank
    LeetCode "Kth Smallest Element in a BST"
    HackerRank
    HackerRank
    LeetCode "Roman to Integer"
    LeetCode "Integer to Roman"
    LeetCode "Majority Element II"
    HackerRank
    HackerRank
  • 原文地址:https://www.cnblogs.com/format/p/1749940.html
Copyright © 2011-2022 走看看