【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.2.5.1.16 file::Write
Contents
Description
Write data from a buffer into the file associated with the file object.
Syntax
UINT Write( const void * lpBuf, UINT nCount )
Parameters
- lpBuf
- [input] A buffer where the data to be written is stored.
- nCount
- [input] The number of bytes to write from the buffer to the file indicated by the File object. Carriage return-line feed character combinations are counted as one byte.
Return
The number of bytes written to the file from the buffer.
Examples
EX1
//write the 1st column of active worksheet with dataset //assume all elements of the column are numeric. int file_Write_ex1() { file ff; bool bOK = ff.Open("C:\\test.txt", file::modeCreate | file::modeReadWrite); if(!bOK) { out_str("Failed to open file C:\test.txt"); return 0; } Worksheet wks = Project.ActiveLayer(); Column cc; if(wks) cc = wks.Columns(0); else out_str("Iinvalid worksheet"); //get data cc.SetInternalData(FSI_DOUBLE); Dataset ds(cc); int nDataSize = 5; ds.SetSize(nDataSize); //write data int nRead = ff.Write(ds, nDataSize * sizeof(double)); return 1; }
EX2
int file_Write_ex2() { file ff; bool bOK = ff.Open("C:\\test.txt", file::modeCreate | file::modeReadWrite); if(!bOK) { out_str("Failed to open file C:\test.txt"); return 0; } int ia = 10; ff.Write(&ia, sizeof(ia)); //write 4 to file. int ib[4] = {1, 2, 3, 4}; ff.Write(ib, sizeof(ib)); //write 1, 2, 3, 4 to file following previous 4. //write double double da = 123.345; ff.Write(&da, sizeof(da)); //write structure WIN32_FIND_DATAA sa; memset(&sa, 0, sizeof(WIN32_FIND_DATAA)); sa.dwFileAttributes = 20000; sa.ftCreationTime.dwLowDateTime = 10; sa.ftCreationTime.dwHighDateTime = 50; sa.ftLastAccessTime.dwLowDateTime = 100000; sa.ftLastAccessTime.dwHighDateTime = 500000; sa.ftLastWriteTime.dwLowDateTime = 1000; sa.ftLastWriteTime.dwHighDateTime = 5000; sa.nFileSizeHigh = 9000000; sa.nFileSizeLow = 1; sa.dwReserved0 = 600; sa.dwReserved1 = 98745; lstrcpy(sa.cFileName, "C:\\Origin70\\OriginC\\origin.h"); lstrcpy(sa.cAlternateFileName,"originc.h"); ff.Write(&sa, sizeof(sa)); //write char array char ca[20] = "This is a string."; ff.Write(ca, sizeof(ca)); //write vector vector<int> ik = {1, 2, 3, 4, 5}; int size = sizeof(int) * ik.GetSize(); ff.Write(ik, size); ff.Close(); return 1; }
Remark
See Also
File::Read, StdioFile::WriteString
Header to Include
origin.h