首页 > 其他分享 >在Non-Mfc下使用CString

在Non-Mfc下使用CString

时间:2023-06-09 17:05:51浏览次数:32  
标签:Non Mfc CString use application non include your


Users of Visual Studio 2003 and newer may directly go to below and skip this one.


//z 2012-1-13 10:36 is2120

方法一
- - -

Q: How to use 'CString' in non-MFCapplications?

A: In most cases, you don't need to do that. In order to use 'CString'you have to statically or dynamically link your application to theentireMFC. This would not only increase the size of your executable file, the numberof its dependencies, but also makes your program non-portable (especially if itis a Console application).

The recommended solution is to use the Standard C++ Class 'std::string'. It isas powerful as 'CString', is portable, using it does not imply adding a hugeamount of things you don't need to your project and last, but not least, it ispartof the programming language.

This being said, if you still want to use 'CString' in your non-MFCapplication, here it is whar you have to do:

  • Include 'afx.h' in one of your main headers
  • Open the menu 'Project -> Settings'. On the 'General' register of the settings dialog box choose 'Use MFC in a Shared DLL' or 'Use MFC in a Static Library' from the dropdown box called 'Microsoft Foundation Classes'.
  • Rebuild your project.

A simple sample of a console application using 'CString'looks like this:

Code:


#include<afx.h>
#include<iostream>
 
intmain()
{
 CString s("Hello");
 std::cout << s.GetBuffer(0) << std::endl;
 return 0;
}


//z 2012-1-13 10:36 is2120@
方法二:从vs2003开始,你可以使用 <atlstr.h>
Starting VS 2003, you can useCString in non-MFC applications by including header atlstr.h:

Code:
 
#include <atlstr.h>
 
A sample console application withCString:
Code:
 
#include <atlstr.h>
#include <iostream>
 
int main ()
{
CString strTest (_T("This is aCString in a console application!"));
 
#ifdef UNICODE
  std::wcout << (LPCTSTR)strTest;
#else
  std::cout << (LPCTSTR)strTest;
#endif
 
return 0;
}


You canalso use CStringA as a ANSI string class, and CStringW as a wide-characterstring class.



方法三:可以使用 boost 中的 string


BoostString Algorithms Library


//z 2012-1-13 10:36 is212

标签:Non,Mfc,CString,use,application,non,include,your
From: https://blog.51cto.com/u_16156420/6449411

相关文章

  • assert vs. ASSERT(mfc) vs. VERIFY
       assertvs.ASSERT(mfc)区别   1.首先assert是c标准里的一个宏,而ASSERT是MFC的一个宏。   2.assert可以通过NDEBUG来关闭。   3.assert在debug版本和release版本里都可用,另两个宏_ASSERT和_ASSERTE   只有当_DEBUG标志被定义的情况下才......
  • 【已解决】可视化ValueError Cannot mask with non-boolean array containing NA NaN
    bug:raiseValueError(na_msg)ValueError:Cannotmaskwithnon-booleanarraycontainingNA/NaNvalues对应的代码:asian_countries=region_data.dropna(subset=['CountryCode'])[region_data['Region'].str.contains('Asia')][&......
  • English Learning Articles 2023-06-07 Nonsurgical cat contraception could help cu
    Nonsurgicalcatcontraceptioncouldhelpcurboverpopulation,studysaysThereareanestimated600milliondomesticcatsintheworld,and80%ofthemareferalorstrayanimals.Spayingandneuteringcatshelpspreventhomelesskittensandovercrowdeda......
  • 基于mfcc和DTW语音信息特征提取算法matlab仿真
    1.算法仿真效果matlab2022a仿真结果如下:2.算法涉及理论知识概要在语音识别(SpeechRecognition)和话者识别(SpeakerRecognition)方面,最常用到的语音特征就是梅尔倒谱系数(Mel-scaleFrequencyCepstralCoefficients,简称MFCC)。根据人耳听觉机理的研究发现,人耳对不同频率的声波有不......
  • 基于mfcc和DTW语音信息特征提取算法matlab仿真
    1.算法仿真效果matlab2022a仿真结果如下:   2.算法涉及理论知识概要       在语音识别(SpeechRecognition)和话者识别(SpeakerRecognition)方面,最常用到的语音特征就是梅尔倒谱系数(Mel-scaleFrequencyCepstralCoefficients,简称MFCC)。根据人耳听觉机理的研究发......
  • ERROR 1418 (HY000) at line 1323: This function has none of DETERMINISTIC, NO SQL
    ERROR1418(HY000)atline1323:ThisfunctionhasnoneofDETERMINISTIC,NOSQL,orREADSSQLDATAinitsdeclarationandbinaryloggingisenabled(you*might*wanttousethelesssafelog_bin_trust_function_creatorsvariable) 开启了bin-log,我们就必须指定......
  • 拓扑错误:自交。jts.geom.TopologyException: found non-noded intersection between L
    Thatbeingsaid,youwillwanttoensurethegeometriesarevalidbeforecomputingtheintersection,using polygon1.isValid() and polygon2.isValid().Thesampledatafor polygon2 isself-intersecting,sotheintersectionoperationfailswithcom.vividso......
  • 实验 透视表 计数 len np.count_nonzero 正确与否
    实验透视表计数 len np.count_nonzero正确与否结果:len正确 np.count_nonzero错误结论:除去三行干扰行(原值均为缺失值)以外:未过账中,有1行无业务员名称无业务员名称中,有1行未过账即:未过账且无业务员名称有1行未过账且有业务员名称有57行已过账且无业务员名称有57行最......
  • Gym - 100519I [NONE]
    题目链接:https://vjudge.net/problem/Gym-100519I 解题思路:先挂在这里#include<bits/stdc++.h>#defineinf0x3f3f3f3fusingnamespacestd;typedeflonglongll;constintmx=3e5+10;boolvis[mx];inttop,pri[mx];voidinit(){ for(inti=2;i<mx;i++){ if(!vis[i......
  • c++11: all_of 、 any_of 和 none_of
    有效的字母异位词classSolution{public:boolisAnagram(strings,stringt){if(s.size()!=t.size())returnfalse;intans[26]={0};for(auto&ch:s){++ans[ch-'a'];}for(auto&......