Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

請問mfc和c整合的觀念

0 views
Skip to first unread message

小飛

unread,
Apr 25, 1999, 3:00:00 AM4/25/99
to

我在整合時,我有一路徑的檔案是CString型態..

那我在用fopen()此函數時,我查看help內的說明..

發現..此函數內的檔案名稱只能用char的型態..如下:


FILE *fopen( const char *filename, const char *mode );

所以是否我用CString的型態..就無法開啟檔案呢?

如果不行..在MFC內..不是都用CString來取代了char嗎?

那利用哪種方法處理會比較好呢?

(將CString的型態再轉成char型態嗎?還是有可以用CSting開檔的函數呢)

--
◎ [1;31m龍 [32m貓 [33m資 [34m訊 [35m天 [36m地 [0m( [1mbbs.mgt.ncu.edu.tw [0m)
◎[ [1;33;46mpswant [0m]來自: 140.115.228.10

何陋居主

unread,
Apr 25, 1999, 3:00:00 AM4/25/99
to
==> 在 pswan...@bbs.mgt.ncu.edu.tw (小飛) 的文章中提到:

> 我在整合時,我有一路徑的檔案是CString型態..
> 那我在用fopen()此函數時,我查看help內的說明..
> 發現..此函數內的檔案名稱只能用char的型態..如下:
> FILE *fopen( const char *filename, const char *mode );
> 所以是否我用CString的型態..就無法開啟檔案呢?

MFC 的 CString class 有一個轉型運算子:

operator LPCTSTR() const;

所以你可以直接把 CString 物件餵給 fopen() 函數。

> 如果不行..在MFC內..不是都用CString來取代了char嗎?
> 那利用哪種方法處理會比較好呢?
> (將CString的型態再轉成char型態嗎?還是有可以用CSting開檔的函數呢)

你也可以使用 MFC 的 CFile class 來處理檔案。
不過奇怪的是:CFile 的建構式參數及開檔參數, 居然沒有 CString 的版本,
仍然是 LPCTSTR 的版本。

--
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
≡ 何陋居 ≡ 好好地陳述問題,問題就等於解決了一半。 俗 語
愚蠢的問題,得到愚蠢的答案,那是報應。 Milton Friedman
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>

Cheng-jen Tang

unread,
Apr 25, 1999, 3:00:00 AM4/25/99
to

何陋居主 <willi...@cis.nctu.edu.tw> wrote in message
news:3UCPfR$3...@bbs.cis.nctu.edu.tw...

> MFC 的 CString class 有一個轉型運算子:
>
> operator LPCTSTR() const;
>
> 你也可以使用 MFC 的 CFile class 來處理檔案。
> 不過奇怪的是:CFile 的建構式參數及開檔參數, 居然沒有 CString 的版本,
> 仍然是 LPCTSTR 的版本。

傳指標反正 const CString* 或 const char* 分別不大
我想他們並沒有做 "預測使用" (在 CFile::CFile() 或 CFile::Open() 裡;
LPCTSTR 是否有機會代入另一 CString 物件? )的 "最佳化設計"
事實上 我也不知道有沒有這方面的研究 這應該是 Design Phase 的
動作 有時這部份的最佳化是比編譯時重要多了
嗯, To be (CString) or not to be; that is the question ?


0 new messages