win32控制台程式中使用CString和string

來源:互聯網
上載者:User

本文轉載自:http://www.pulog.org/Ori/27/vc-cstring/

最近編一個控制台程式,開始時用字元數組,發現處理字串很不方便.於是想到用MFC的CString類.CString的標頭檔是<afxwin.h>.包含標頭檔編譯,提示錯誤fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>.後來幾經周折終於找到瞭解決辦法:
一,在工程->設定->常規選項 選擇使用MFC做為靜態連結庫或做為共用的DLL.

 

(DavidLee91:)在vs2008中,設定方法為:項目—項目名屬性—配置屬性—常規—MFC的使用—在共用DLL中使用MFC

二#include <afxwin.h>必須放在#include <winsock2.h>等檔案的前邊,具體是什麼檔案還沒弄清楚.
所以為了方便還是把#include <afxwin.h>放在其它標頭檔的前邊比較好.
  使用string的方法是:在標頭檔中包含這兩句#include <string>  
   using namespace std; 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.