image
專案設定Common Language Runtime Support預設值為No Common Language Runtime Support改選擇支援Common Language Runtime(/clr)設定clr完成後編輯程式才會自動出現對應的提示字,否則會不認得namespace System及System::IO
 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: }

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
CRT(C執行時期函式庫)在編譯前須先設定preprocessor, 加入_CRT_SECURE_NO_WARNINGSCRT安全版: 增加參數驗證, 緩衝區大小檢查, 格式化參數驗證功能寫入fprintf_s讀取fscanf_s
 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:  

me1237guy 發表在 痞客邦 留言(0) 人氣()

利用ofstream寫入檔案, ifstream讀入檔案
很明顯用標準函式庫比上一篇(Windows API WriteFile and ReadFile)使用Windows API語法簡單易懂多了!!!

me1237guy 發表在 痞客邦 留言(0) 人氣()

使用WindowsAPI進行WriteFile 和 ReadFile應用程式  ---> Windows API –—> Windows 作業系統
 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: }

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
開啟新專案
專案名稱: VS2012ConsoleOpenCV248

按下<Next>按鈕

me1237guy 發表在 痞客邦 留言(1) 人氣()

image
工具->選項->文字編輯器->所有語言->勾選<行號>

設定字體

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
新版OpenCV 2.4.8發行囉!!!
直接Extract到C:\OpenCV-2.4.8\

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
從FormCreate後開始判斷是否有註冊過?
 

RegDate是否存在, 不存在則寫入目前日期當作註冊日
如果目前日期<上一次寫入regedit日期, 則視為異常:使用者有調整 –>關閉程式
檢查目前日期與到期日期剩餘天數, 若<0則關閉程式

me1237guy 發表在 痞客邦 留言(0) 人氣()

image
這幾天發現再戰十年的WinXP執行OpenCV2.4.7應用程式時發生一個錯誤訊息
InitializeCriticalSectionEx 找不到程式入口點, 在kernel32.dll發生錯誤…
嘗試1. 於是便循著kernel32.dll關鍵字去找, 下載dll結果徒勞無功
嘗試2. 以為是win7下編譯的程式在winxp會有問題, 於是VMware搞一個winxp作業環境來試試,

me1237guy 發表在 痞客邦 留言(0) 人氣()

image





me1237guy 發表在 痞客邦 留言(0) 人氣()

image
今天很高興參加C++ Builder for iOS預覽發表會, 現場有李維大師親自講解有關C++ Builder的發展。
面對當前二十一世紀, WINDOWS不在獨霸, 取而代之的是更多元的作業系統;
也因此, 工程師面臨更嚴峻的考驗, 該學新的工具或程式語言for特定的硬體/作業系統嗎?

me1237guy 發表在 痞客邦 留言(0) 人氣()

image_thumb1
新增一個<空的Qt專案>

輸入名稱:HorzVertLayout

me1237guy 發表在 痞客邦 留言(0) 人氣()

Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。