一、CString库的使用
1. MFC CString类库的典型实例
#include <afx.h> //包含MFC CString类库
#include <iostream>
using namespace std;
int main()
{
CString str;
double a = rand()%100;
double b = rand()%100;
double c = rand()%100;
str.Format("%0.3f*%0.3f=%0.3f\n", a, b, a * b);
cout<< str <<endl;
return 0;
}
报错:fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version)
方案: 项目、属性、配置属性、常规,右边“项目默认值”、MFC使用,选择“在共享 DLL 中使用 MFC”
2. 实例2
#include <afx.h> //包含MFC CString类库
#include <iostream>
using namespace std;
int main()
{
CString str;
string datastr;
double a = rand()%100;
double b = rand()%100;
double c = rand()%100;
str.Format("%0.3f*%0.3f=%0.3f\n", a, b, a * b);
datastr=LPCSTR(str); //CString类型转换为string类型
cout<< datastr <<endl;
return 0;
}
报错:error C2679: 二进制“<<”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)
方案:添加声明 #include "string"
参考:https://blog.csdn.net/bitxinhai/article/details/2292014 CString/string 区别及其转化
3. 最后:还是放弃了使用MFC CString库,因为afx.h与另一个库有重定义。而另一个库又不得不用。
在非MFC框架下使用MFC 库还是太麻烦。
二、C++代码生成
1、位置:项目——属性——配置属性——C/C++——代码生成
2、规则:所有项目的这个"代码生成"属性设置保持一致。
有/MT,/MTd,/Md,/MDd四个选项,必须让所有使用的库都使用相同的配置,否则就会有相应的提示,甚至可能会出现无法解析的函数。有时我们使用的库不是自己可以控制的,那么就只能把工程属性设置成河你使用的库相同的选项。
详细:https://blog.csdn.net/lwwl12/article/details/77045717 vc++编译时运行库选择(/MT、/MTd、/MD、/MDd)
参考:https://blog.csdn.net/roslei/article/details/70310194 静态编译

被折叠的 条评论
为什么被折叠?



