读书人

VS2010 c++ 异常的处理方法

发布时间: 2012-08-24 10:00:20 作者: rapoo

VS2010 c++ 错误的处理方法

1错误:

fatal error C1010: unexpected endof file while looking for precompiled header. Did you forget toadd '#include"StdAfx.h"' to your source?

#include"StdAfx.h" 你把这个放在头文件里面就行了

2 vc++编程出现错误error C2447: missing function header (old-styleformal list?)

原因:函数后面多了分号;

SUNSHINE_APISSN_RETURN SsnWriteProfileString(__in INT nPlugInId, __in_opt LPTSTRlpszGroupName, __in LPTSTR lpszKey, __in LPTSTR lpszValue);

3 errorC2491: 'SsnWriteProfileString' : definition of dllimport function not allowed

错误C2491:“SsnWriteProfileString’:dllimport函数的定义不允许的

SUNSHINE_API SSN_RETURNSsnWriteProfileString(__in INT nPlugInId, __in_opt LPTSTR lpszGroupName, __inLPTSTR lpszKey, __in LPTSTR lpszValue)

查看SUNSHINE_API在 .h文件中的定义

#ifdefSSNAPI_EXPORTS

#define SUNSHINE_API __declspec(dllexport)

#else

#define SUNSHINE_API __declspec(dllimport)

#endif

将#ifdef SSNAPI_EXPORTS添加到#include<stdafx.h>的下面;形如:

#include<stdafx.h>

#defineSSNAPI_EXPORTS

则解决;

4 error C2065: “CString”:未声明的标识符

在非mfc下使用CString 会导致上面错误:

解决办法:

(1)如果你使用VC.net那么:使用MFC:包含cstringt.h;不使用MFC:包含atlstr.h

(2)或者 #include <afx.h>

5 error C2065: 'DEBUG_NEW' : undeclared identifier?

删除 .cpp 文件中的

#ifdef _DEBUG

#undef THIS_FILE

static char THIS_FILE[]=__FILE__;

#define new DEBUG_NEW

#endif

6 问题:

error C2440: 'initializing' : cannot convert from 'constchar [34]' to 'TCHAR [128]'

错误C2440:“初始化”:不能把'字符常量[34]' ' TCHAR[128]'

原因:编译选项有没有开了UNICODE;

做法:

在vs2010下设置unicode编译选项,去掉unicode模式,具体设置方法为:

项目-》属性-》配置属性-》字符集-》未设置

project->Properties->ConfigurationProperties->General->Character Set->Not Set

http://blog.csdn.net/hrh2010/article/details/6681271

7问题:

C1083:Cannot open include file: 'stdafx.h': No such file or directory

C1083:无法打开包括文件:“stdafx.h中”:没有这样的文件或目录

解决:stdafx.h文件和工程的.h文件放在一个位置;

8 error C2065: “cout”: 未声明的标识符

解决方法:加上

#include <iostream>

using namespace std;

9 错误:

error C3872: '0x3000': thischaracter is not allowed in an identifier

错误C3872:'0 X3000“:此字符不允许在标识符

0x3000是汉语的空格,也就是全角空格,相当于一个汉字,但你又看不见它。

你知道的,像逗号,有半角(,)和全角(,)之分的,其实空格也有。

0x3000是全角的空格,0x20是半角的空格。

你最好把这个语句的后面空白部分,都删除掉,免得有不可见的全角空格。

10 加上 _T

error C2664: 'intswprintf_s(wchar_t *,size_t,const wchar_t *,...)' : cannot convert parameter 3from 'const char [24]' to 'const wchar_t *'

错误C2664:' int swprintf年代(wchar t *,大小t,t * wchar const,…)“:不能转换参数3从“const char[24]”到“const wchar t *’

_stprintf_s(filename,MAX_PATH, _T("C:\\Program\\rwini_%d.ini"),nPlugInId);

_T("C:\\Program\\rwini_%d.ini") 相当于 LPTSTR

11无法打开预编译头文件的解决方法

编辑程序,按Ctrl+F7,出现下列错误:

fatal error C1083: 无法打开预编译头文件:“Debug/UGFace.pch”: No such file or directory

解决方法:修改:项目->属性->C/C++->预编译头->不使用预编译头即可。

12

1>inifile.obj :error LNK2019: unresolved external symbol "private: __thiscallCsaveFileNameA::CsaveFileNameA(class CFileNameA *,classstd::basic_string<char,struct std::char_traits<char>,classstd::allocator<char>> const &)"(??0CsaveFileNameA@@AAE@PAVCFileNameA@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)referenced in function "public: class CsaveFileNameA * __thiscallCFileNameA::AddFileName(class std::basic_string<char,structstd::char_traits<char>,class std::allocator<char>>)"(?AddFileName@CFileNameA@@QAEPAVCsaveFileNameA@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

错误是CsaveFileNameA没有实现,即没有写CsaveFileNameA构造函数和析构函数

13

1>e:\gc\src\core\inifile.h(344):error C2143: syntax error : missing ';' before '*'

错误原因

CIniFileW* PIniFile;应用的类在该类的下面,未定义;

classCFileNameW

{

public:

staticconstwchar_t*const LF;

public:

CFileNameW();

~CFileNameW();

classCsaveFileNameW

{

friendclassCFileNameW;

#ifdef _WIN32

// Added forversions earlier than VS2008

#ifdefined(_MSC_VER) && (_MSC_VER <= 1400)

friendstructci_less_w;

#endif

#endif

private:

CsaveFileNameW( CFileNameW* pIniFile , const std::wstring& sFileName );

CsaveFileNameW( constCsaveFileNameW& );// No Copy

CsaveFileNameW&operator=(constCsaveFileNameW&);// No Copy

~CsaveFileNameW();

private:

CFileNameW* m_pIniFile;

std::wstring m_sFileName;

CIniFileW* PIniFile;

};

structci_less_w

{

booloperator()(const CsaveFileNameW* s1,const CsaveFileNameW* s2) const

{

#ifndef _WIN32

returnwcscasecmp(s1->m_sFileName.c_str(), s2->m_sFileName.c_str()) < 0;

#else

return_wcsicmp(s1->m_sFileName.c_str(), s2->m_sFileName.c_str()) < 0;

#endif

}

};

typedefstd::set<CsaveFileNameW*,ci_less_w> FileIndexW;

#ifdef _WIN32

#ifdefined(_MSC_VER) && (_MSC_VER >= 1200)&& (_MSC_VER < 1300)

friendclassCsaveFileNameW;

#endif

#endif

public:

CsaveFileNameW* GetFileName( std::wstringsFileName );

//CsaveFileNameW*GetFileName( std::wstring sFileName ) const;

FileIndexW::const_iterator _find_file( const std::wstring& sFileName ) const;

FileIndexW::iterator _find_file( conststd::wstring& sFileName );

voidRemoveAllFileNames( );

private:

FileIndexW m_filenames;

};

classCIniFileW

{

public:

staticconstwchar_t* const LF;

public:

CIniFileW();

~CIniFileW();

// Usedto save the data back to the file or your choice

bool Save( conststd::wstring& fileName );

修改在前面加上 class CIniFileW

即为:

classCIniFileW;

classCFileNameW

{

public:

staticconstwchar_t*const LF;

public:

CFileNameW();

~CFileNameW();

classCsaveFileNameW

{

friendclassCFileNameW;

#ifdef _WIN32

// Added forversions earlier than VS2008

#ifdefined(_MSC_VER) && (_MSC_VER <= 1400)

friendstructci_less_w;

#endif

#endif

private:

CsaveFileNameW( CFileNameW* pIniFile , const std::wstring& sFileName );

CsaveFileNameW( constCsaveFileNameW& );// No Copy

CsaveFileNameW&operator=(constCsaveFileNameW&);// No Copy

~CsaveFileNameW();

private:

CFileNameW* m_pIniFile;

std::wstring m_sFileName;

public:

CIniFileW* PIniFile;

};

structci_less_w

{

booloperator()(const CsaveFileNameW* s1,const CsaveFileNameW* s2) const

{

#ifndef _WIN32

returnwcscasecmp(s1->m_sFileName.c_str(), s2->m_sFileName.c_str()) < 0;

#else

return_wcsicmp(s1->m_sFileName.c_str(), s2->m_sFileName.c_str()) < 0;

#endif

}

};

typedefstd::set<CsaveFileNameW*,ci_less_w> FileIndexW;

#ifdef _WIN32

#ifdefined(_MSC_VER) && (_MSC_VER >= 1200)&& (_MSC_VER < 1300)

friendclassCsaveFileNameW;

#endif

#endif

public:

CsaveFileNameW* GetFileName( std::wstringsFileName );

//CsaveFileNameW*GetFileName( std::wstring sFileName ) const;

FileIndexW::const_iterator _find_file( const std::wstring& sFileName ) const;

FileIndexW::iterator _find_file( conststd::wstring& sFileName );

voidRemoveAllFileNames( );

private:

FileIndexW m_filenames;

};

classCIniFileW

{

public:

staticconstwchar_t* const LF;

public:

CIniFileW();

~CIniFileW();

// Usedto save the data back to the file or your choice

bool Save( conststd::wstring& fileName );

14

error C2248:'CFileNameW::CsaveFileNameW::PIniFile' : cannot access privatemember declared in class 'CFileNameW::CsaveFileNameW'

错误C2248:“CFileNameW::::PIniFileCsaveFileNameW”:不能访问私有成员中声明的类的CFileNameW::CsaveFileNameW”

改正:把PIniFile改成公有的;

public:

CIniFileW* PIniFile;

读书人网 >VSTS

热点推荐