在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错误的更多相关文章

  1. Windows_Program_Via_C_Translate_Win32编程的背景知识/基础知识_包括基本输入输出机制介绍

    Some Basic Background Story of The Win32 APIs Win32 API背景故事/背景知识 The Win32 application programming i ...

  2. 航空概论(历年资料,引之百度文库,PS:未调格式,有点乱)

    航空航天尔雅 选择题1. 已经实现了<天方夜谭>中的飞毯设想.—— A——美国2. 地球到月球大约—— C 38 万公里3. 建立了航空史上第一条定期空中路线—— B——德国4. 对于孔明 ...

  3. error C2065:未声明的标识符错误

    原文地址:http://blog.sina.com.cn/s/blog_8216ada701017evx.html 在VS2010下进行VC++调试时,出现这样一种错误:error C2065:未声明 ...

  4. error C2664 转换错误汇总[转]

    vs2005提示 error C2664: “CWnd::MessageBoxW”: 不能将参数 1 从“const char [17]”转换为“LPCTSTR”. 在用vs2005编写mfc程序的时 ...

  5. VC++编译错误error C2065: “HANDLE”: 未声明的标识符及添加winbase.h后提示winbase.h(243): error C2146: 语法错误: 缺少“;”(在标识符“Internal”的前面)的解决办法

    问题描述: VC++程序编译时提示错误:error C2065: “HANDLE”: 未声明的标识符等众多错误提示,如下所示: error C2065: “HANDLE”: 未声明的标识符 error ...

  6. error C2065:!错误:未定义标识符“pBuf);”

    error C2065: “pBuf):”: 未声明的标识符 错误原因:第二个括号)使用的是中文符号!还有最后那个分号! 改回来就好了~ 原错误: 修正后错误消失:

  7. MFC 错误异常,用vs添加资源并为资源定义类后报错:error C2065 : 未声明的标识符

    添加了一个Dialog资源,修改了ID之后右击资源添加了一个类,在类里面有一个成员变量: // 对话框数据    enum { IDD = IDD_GETIN }; 而在编译过程中出现报错,错误代号是 ...

  8. 引用其他头文件时出现这种错误,莫名其妙,error C2065: “ColorMatrix”: 未声明的标识符

    今天做项目时,直接拷贝了另一个工程里的头文件和源文件,然后运行时就出现这种问题,莫名其妙,在原程序里运行一点问题就没有,但是在新工程里就是error. >e:\c++\button_fly2\b ...

  9. 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 ...

随机推荐

  1. UVA 10400 Game Show Math (dfs + 记忆化搜索)

    Problem H Game Show Math Input: standard input Output: standard output Time Limit: 15 seconds A game ...

  2. mysql连接提示1030

    今天上午,开发使用工具连上mysql,连接一个库,就提示 mysql 错误 ERROR 1030 Got error 28 from. 查询资料,说可能是磁盘空间不足.果然连上去一看/分区空间只有数十 ...

  3. 作为java应届生,面试求职那点事

    找工作两星期多了.心情不爽,写点记录打发时间. 嘘~~自己的破事:  刚毕业,也过了实习,本理所应当的留在公司转正.可是为了谈了两年的女朋友回家见面.一切都顺利进行,妈妈也开心给了一万见面礼,一切都以 ...

  4. C++中的cout输出机制

    代码: #include <iostream> using namespace std; int hello(){ cout<<"hello"<< ...

  5. JS常用的方法

    1.时间戳转换 //时间戳(有Date和无Date的都可)转换为日期 “2016年5月30日 10:29:30 2016-05-20 09:11” function TimeConversion(ti ...

  6. 在js中使用json

    在js中使用json var obj = {     "1" : "value1",     "2" : "value2" ...

  7. CSS实现背景透明/半透明效果的方法

    全透明代码:{background:transparent} 半透明代码:{filter:alpha(opacity=80);-moz-opacity:0.8;width:auto !importan ...

  8. python代码风格规范

    类注释模板: :: class AnotherClass: """ 类注释 """ def method(self, arg1, arg2, ...

  9. The Suspects(POJ 1611 并查集)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 30158   Accepted: 14665 De ...

  10. 用RBG颜色设置自定义颜色

    这个是Mac自带的测色计   快捷键shift + command + c即可复制RBG格式的颜色 #DD0000 这个是csdn 的logo里的红色 我们得到的是十六位颜色代码 但是UIColor( ...