在Win32 Console中使用MFC
#include <afx.h>
project--setting--general,MFC设置改为use MFC in a shared dll
CString转string和char*
#include <iostream>
#include <string>
#include "afx.h"
using namespace std;
int main()
{
CString cStr("CString");
//convert a CString to string
string s = CW2A(cStr);
//convert a CString to char *
CW2A newStr(cStr);
char *charArray = newStr;
cout<<cStr<<endl;
cout<<s<<endl;
cout<<charArray<<endl;
getchar();
}
string和char*转CString
#include <iostream>
#include <string>
#include "afx.h"
using namespace std;
int main()
{
char *s = "This is a char* string";
string str = "This is a string";
CString cStr(s);
CString sStr(str.c_str());
getchar();
}