
至Emgu sourceforge下載libemgucv-windows-universal-cuda-2.9.0.1922-beta.exeEmgu官方網頁
預設路徑:C:\Emgu\emgucv-windows-universal-cuda 2.9.0.1922




1: // WriteFileDemo4.cpp : Defines the entry point for the console application.
2: //
3: 4: #include "stdafx.h"
5: using namespace System;
6: using namespace System::IO;
7: 8: int _tmain(int argc, _TCHAR* argv[])
9: {10: // 寫入檔案
11: String^ path = "test.txt";
12: StreamWriter^ sw = File::CreateText(path);13: String^ line = "我要寫入4";
14: sw->WriteLine(line); 15: sw->Close(); 16: 17: // 讀取檔案
18: StreamReader^ sr = File::OpenText(path);19: String^ s = "";
20: if( s = sr->ReadLine())
21: { 22: Console::WriteLine( s ); 23: } 24: Console::ReadLine();25: return 0;
26: }
1: #include "stdafx.h"
2: #include <cstdio>
3: #include <iostream>
4: 5: int _tmain(int argc, _TCHAR* argv[])
6: {7: // 寫入檔案
8: char msg[] = "我要寫入3";
9: FILE *fp;10: printf_s("寫入檔案:\n%s\r\n", msg);
11: fopen_s(&fp, "test.txt", "w");
12: fprintf_s(fp, "%s\n", msg);
13: fclose(fp); 14: 15: // 讀取檔案
16: fopen_s(&fp, "test.txt","r");
17: char line[256];
18: fscanf_s(fp, "%s", line, 256);
19: printf_s("讀取檔案: \n%s\r\n", line);
20: fclose(fp);21: system("pause");
22: return 0;
23: } 24: 1: #include "stdafx.h"
2: #include <Windows.h>
3: #include <iostream>
4: 5: using namespace std;
6: 7: int _tmain(int argc, _TCHAR* argv[])
8: {9: // 寫入檔案
10: HANDLE hFile; 11: DWORD nBytes;12: hFile = CreateFile( _T("test.txt"), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
13: char msg[] = "我要寫入1";
14: if( hFile != INVALID_HANDLE_VALUE)
15: {16: WriteFile(hFile, msg, sizeof(msg)-1, &nBytes, NULL);
17: CloseHandle(hFile);18: cout << "寫入內容: " << msg << endl;
19: 20: cout << "寫入 " << nBytes << " Bytes" << endl;
21: system("pause");
22: }23: //-------------------------------------------------
24: // 讀取檔案
25: hFile = CreateFile( _T("test.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
26: if(hFile != INVALID_HANDLE_VALUE )
27: {28: char line[256] = {0};
29: BOOL bResult;30: bResult = ReadFile(hFile, line, sizeof(line), &nBytes, NULL);
31: if(nBytes!=0)
32: {33: cout << "讀入內容: " << endl;
34: cout << line << endl; 35: } 36: CloseHandle(hFile);37: system("pause");
38: }39: return 0;
40: }

