vc10的C2664和C2065错误
在vs2010中编译一个普通的C++程序(Win32 Console Application),都会出现这两个错误!
究其原因是:我们已经习惯了VC6的种种简陋和不规范!
例如,下列程序在VC6中编译通过。
主程序:testCir2.cpp
// testCir2.cpp : Defines the entry point for the console application.
// #include "stdafx.h" #include "circular.h"
#include <stdlib.h>
#include <iostream.h> int main(int argc, char* argv[])
{
const double Pi = 3.14;
double dRadius = 3;
if (argc > 1) {
dRadius = atof(argv[1]);
} cout<<"你输入的半径为: "<<dRadius<<endl; Circular *circular = new Circular(Pi); double dArea = circular->getArea(dRadius);
cout<<"面积为:"<<dArea<<endl; double dCircumference = circular->getCircumference(dRadius);
cout<<"周长为:"<<dCircumference<<endl; return 0;
}
但是在vc10中就会出现:
1. C2664: 'atof' : cannot convert parameter 1 from '_TCHAR *' to 'const char *'
dRadius = atof(argv[1]); // vc6 // C2664: 'atof' : cannot convert parameter 1 from '_TCHAR *' to 'const char *'
原因是:VC10中使用了unicode定义的变量;我们的MBCS定义的函数无法进行转换工作。
TCHAR.H routine |
_UNICODE & _MBCS not defined |
_MBCS defined |
_UNICODE defined |
---|---|---|---|
_tstof |
atof |
atof |
_wtof |
_ttof |
atof |
atof |
_wtof |
更改为:
dRadius = _wtof(argv[1]);
即可解决C2664错误。
2. C2065: 'cout' : undeclared identifier
C2065: 'endl' : undeclared identifier
我们经常使用的cout和endl怎么变成了不识别的了?
原因是:VC10给标准函数使用了命名空间。
解决方法有2种:
(1) 强制使用命名空间
using namespace std;
(2) 在标准函数前加前缀
std::cout<<"你输入的半径为: "<<dRadius<<std::endl;
最后,要注意引用的不同:
VC6:
#include <stdlib.h> // vc6 - atof()
#include <iostream.h> // vc6 - cout // vc6 - endl
VC10:
// vc10 - cout & endl
using namespace std;
#include <iostream>
--------------------------------------------------------------xiaobin_hlj80--------------------------
附:类文件
头文件:circular.h
// circular.h: interface for the Circular class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX_CIRCULAR_H__612399AD_E8A7_433A_BD63_6C1F29BAC83E__INCLUDED_)
#define AFX_CIRCULAR_H__612399AD_E8A7_433A_BD63_6C1F29BAC83E__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 class Circular
{
public:
Circular(double pi);
virtual ~Circular(); double PI; double getArea(double radius); double getCircumference(double radius); }; #endif // !defined(AFX_CIRCULAR_H__612399AD_E8A7_433A_BD63_6C1F29BAC83E__INCLUDED_)
源文件:circular.cpp
// circular.cpp: implementation of the Circular class.
//
////////////////////////////////////////////////////////////////////// #include "stdafx.h"
#include "circular.h" //////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Circular::Circular(double pi)
{
PI = pi;
} Circular::~Circular()
{ } double Circular::getArea(double radius) {
return PI * (radius * radius);
} double Circular::getCircumference(double radius) {
return PI * (radius * 2);
}
vc10的C2664和C2065错误的更多相关文章
- Windows_Program_Via_C_Translate_Win32编程的背景知识/基础知识_包括基本输入输出机制介绍
Some Basic Background Story of The Win32 APIs Win32 API背景故事/背景知识 The Win32 application programming i ...
- 航空概论(历年资料,引之百度文库,PS:未调格式,有点乱)
航空航天尔雅 选择题1. 已经实现了<天方夜谭>中的飞毯设想.—— A——美国2. 地球到月球大约—— C 38 万公里3. 建立了航空史上第一条定期空中路线—— B——德国4. 对于孔明 ...
- error C2065:未声明的标识符错误
原文地址:http://blog.sina.com.cn/s/blog_8216ada701017evx.html 在VS2010下进行VC++调试时,出现这样一种错误:error C2065:未声明 ...
- error C2664 转换错误汇总[转]
vs2005提示 error C2664: “CWnd::MessageBoxW”: 不能将参数 1 从“const char [17]”转换为“LPCTSTR”. 在用vs2005编写mfc程序的时 ...
- VC++编译错误error C2065: “HANDLE”: 未声明的标识符及添加winbase.h后提示winbase.h(243): error C2146: 语法错误: 缺少“;”(在标识符“Internal”的前面)的解决办法
问题描述: VC++程序编译时提示错误:error C2065: “HANDLE”: 未声明的标识符等众多错误提示,如下所示: error C2065: “HANDLE”: 未声明的标识符 error ...
- error C2065:!错误:未定义标识符“pBuf);”
error C2065: “pBuf):”: 未声明的标识符 错误原因:第二个括号)使用的是中文符号!还有最后那个分号! 改回来就好了~ 原错误: 修正后错误消失:
- MFC 错误异常,用vs添加资源并为资源定义类后报错:error C2065 : 未声明的标识符
添加了一个Dialog资源,修改了ID之后右击资源添加了一个类,在类里面有一个成员变量: // 对话框数据 enum { IDD = IDD_GETIN }; 而在编译过程中出现报错,错误代号是 ...
- 引用其他头文件时出现这种错误,莫名其妙,error C2065: “ColorMatrix”: 未声明的标识符
今天做项目时,直接拷贝了另一个工程里的头文件和源文件,然后运行时就出现这种问题,莫名其妙,在原程序里运行一点问题就没有,但是在新工程里就是error. >e:\c++\button_fly2\b ...
- Visual Studio 2010 error C2065: '_In_opt_z_' : undeclared identifier 编译错误
当用Visual Studio 2010 编译时 发生如下编译错误: 2>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\inclu ...
随机推荐
- PHP5生成图形验证码(有汉字)
利用PHP5中GD库生成图形验证码 类似于下面这样 1.利用GD库函数生成图片,并在图片上写指定字符 imagecreatetruecolor 新建一个真彩色图像 imagecolora ...
- Gson源码分析之Json结构抽象和注解使用
github上的博客地址: http://chuyun923.github.io/blog/2015/01/06/gsonyuan-ma-fen-xi/ XML和Json作为最常用的两种网络传输格式而 ...
- Some good iOS questions
这里,我列举了一些在Stackoverflow中一些比较好的关于iOS的问题.大部分我列举的问题都是关于Objective C.所有问题中,我比较喜欢“为什么”这一类型的问题. 问题 1. What’ ...
- ie8 hack
1.‘\9’: eg:.test { color/*\**/: blue\9 }.header {width:300px;} /* 所有浏览器*/.header {width/*\**/:330px\ ...
- memcached session共享
http://www.baidu.com/s?wd=memcached%20session%E5%85%B1%E4%BA%AB&rsv_spt=1&issp=1&f=8& ...
- jwplayer修改logo右键版权
jwplayer二次编译,可以自定义自己的logo和右键版权.
- 关于sql2005 与 myeclipse进行连接出现的小问题
C盘目录下没有jdbc这个文件夹,所以从网上下一个 这个是2008连接jdbc用的 正常解压第一个到相应的目录 主要是注意一个叫tcp/ip的协议,米有找到64位的 点击这里的tcp ip就哦了但是他 ...
- Apache URL转发
httpd.conf 尾巴加 Alias /web "F:\xampp\htdocs\test/" <Directory "F:\xampp\htdocs\test ...
- 影响MySQL性能的五大配置参数
我们今天主要和大家分享的是对MySQL性能影响关系紧密的五大配置参数,以下就是文章的具体内容描述,希望会给你带来一些帮助在此方面. 以下的文章主要是对MySQL性能影响关系紧密的五大配置参数的介绍,我 ...
- 使用yii2实现读写分离(MySQL主从数据库)
读写分离(Read/Write Splitting). 1.原理:让主数据库(master)处理事务性增.改.删操作(INSERT.UPDATE.DELETE),而从数据库(slave)处理SELEC ...