1错误:ios
fatal error C1010: unexpected endof file while looking for precompiled header. Did you forget toadd '#include"StdAfx.h"' to your source?c++
#include"StdAfx.h" 你把这个放在头文件里面就好了编程
2 vc++编程出现错误error C2447: missing function header (old-styleformal list?)windows
缘由:函数后面多了分号;api
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函数的定义不容许的less
SUNSHINE_API SSN_RETURNSsnWriteProfileString(__in INT nPlugInId, __in_opt LPTSTR lpszGroupName, __inLPTSTR lpszKey, __in LPTSTR lpszValue)ide
查看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
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;
15 error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'TCHAR'
修改前:
CString Description;
CString Ddvalue =_T("Command description");
SsnGetLocaleString(SSN_PLUGIN_ID_ANY,Ddvalue, SSN_AUTO_SELECT_LOCALE,NULL,Ddvalue,Description.GetBuffer(), MAX_PATH,Ddvalue);
CString Hotkeys;
CString Hdvalue =_T("Hotkeys");
SsnGetLocaleString(SSN_PLUGIN_ID_ANY,Hdvalue, SSN_AUTO_SELECT_LOCALE,NULL,Hdvalue,Hotkeys.GetBuffer(), MAX_PATH,Hdvalue);
TCHAR rgtsz[2][MAX_PATH]={Description.GetBuffer(),Hdvalue.GetBuffer()};
修改后:
CString Description;
CString Ddvalue =_T("Command description");
SsnGetLocaleString(SSN_PLUGIN_ID_ANY,Ddvalue, SSN_AUTO_SELECT_LOCALE,NULL,Ddvalue,Description.GetBuffer(), MAX_PATH,Ddvalue);
CString Hotkeys;
CString Hdvalue =_T("Hotkeys");
SsnGetLocaleString(SSN_PLUGIN_ID_ANY,Hdvalue, SSN_AUTO_SELECT_LOCALE,NULL,Hdvalue,Hotkeys.GetBuffer(), MAX_PATH,Hdvalue);
TCHAR *rgtsz[2]={Description.GetBuffer(),Hdvalue.GetBuffer()};
给二维数组赋值;
16 warning C4627: '#include <math.h>': skipped when looking for precompiled header use
解决方法:加上头文件#include "stdafx.h"
17
CString与char的转换问题,用强制转换报了以下错误,应该如何进行转换呢?
CString strName;
TCItem.item.pszText= "ok ";//显示正常
TCItem.item.pszText=(char)strName;//报以下错误
error C2440: 'type cast ' : cannot convert from 'class CString ' to 'char '
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
解决方法:
(char *)&strName
18 关于VC 的 error C3872: '0x3000':
今天在网上看到了些技术代码(关于按钮动态生成菜单的代码.好象都是一我的写的吧.几乎都没有什么变化),因而边拷贝代码边测试执行程序的结果,想不到碰到了麻烦,简单的两行代码执行时竟然出了十多行的error提示:
Error 1 error C3872: '0x3000': this character is not allowed in an identifier
可是看上去代码明明是对的,没错啊!因而双击提示查看是哪里出的错,结果光标停在了一行注释上,那是一块儿拷贝进来的一些注释文字。想一想也没用,删除,再运行,结果程序顺利执行完毕了。
后来发现是一些网页上的非正常格式的空格在作怪,应该是字符码的问题,它与VS中的字符不兼容,因此VS编译程序时没法识别此类字符串,因而报错。
注释有的时候就出现莫名其妙的问题..............
19 iostream 的用法,头文件后面不能加.h
#include<iostream>
using namespace std;
20 error LNK2005: "int __cdecl PiShowListDialog(struct _SSN_OBJECT_ID_,struct _SSN_OBJECT_ID_)" (?PiShowListDialog@@YAHU_SSN_OBJECT_ID_@@0@Z) already defined in DlgDefaultList.obj
错误表明同一个工程里,有两个PiShowListDialog函数!
21
致命错误C1010:在寻找预编译指示头文件时,文件未预期结束。
就是没有找到预编译指示信息的头文件。 问题通常发生在:经过添加文件的方式,添加了一些cpp文件到一个MFC的程序,但该cpp文件并非MFC,而是标准的C++。 解决方案1: 右键单击项目工程中的cpp文件,在菜单Project->Settings->C/C++->Precompile Header,设置为第一项:Not using precompile headers。 解决方案2:在.cpp文件开头添加包含文件stdafx.h。 #include"stdafx.h"
22 error C2664: “LoadLibraryW”: 不能将参数 1 从“const char *”转换为“LPCWSTR”
1 静态调用DLL
Project | setting
Link选项卡Library modules处
添加“XXX.lib”
而后#include “XXX.h”
把XXX.lib(引入库文件),XXX.DLL(动态库文件)
XXX.h(头文件)
所有放到工程目录下
2 动态调用DLL
经过
LoadLibrary
GetProcAddress
FreeLibrary实现。
缘由 :工程只支持UNICODE字符
解决方法:
一、工程属性->配置属性–>常规—>字符集—->使用多字节符字符集
二、也就是宽字符,因此下面这行代码,应该编译有错误
hinst=LoadLibrary(“InTheHand.Net.Personal.dll”);
也就是:
cannot convert parameter 1 from ‘char [27]‘ to ‘const unsigned short *’
楼主将代码改成:
hinst=LoadLibrary(L”InTheHand.Net.Personal.dll”);
或者
hinst=LoadLibrary(_T(“InTheHand.Net.Personal.dll”));
试试
22
warning C6387: 'argument 1' might be '0': this does not adhere to the specification for the function 'GlobalLock': Lines: 328, 329, 330, 332, 333, 334, 335
就是未对输入是否为空,进行判断!
23
AfxMessageBox(("click"));
错误 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types
解决方法:
AfxMessageBox(_T("click"));
解释:若是程序中define _UNICODE,则可用_T or _TEXT将后面的内容转为UNICODE格式字符串,不然和不用_T同样
或者就修改项目属性里面的字符编码
24 LNK2005: "class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > NextSpeakString" (?NextSpeakString@@3V?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@A) already defined in Speech.obj
解决方案:变量或者函数的定义放到cpp文件中,不要放到.h中~
25 :\ceshi\fuzzysearch\fuzzysearch\fuzzysearch\fuzzysearch.cpp(46): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)
老是提示这样的错误,修改方法:
(1)加上头文件#include <string>
(2)检查类型:
TCHAR* argv[100];
std::cout<<"输入数组大小"<<endl;
std::cin>> argc;
std::cout<<"输入数组内数据"<<endl;
for(int j=0;j<argc;j++)
{
std::cin>>argv[j];
}
则提示错误,应该改为: char* argv[100]; 则再也不提示此错误;
转自:http://blog.csdn.net/powerlly/article/details/4409592
1. 解决error LNK2005: ___crtExitProcess 已经在 LIBCMTD.lib(crt0dat.obj) 中定义
有的時候, 在 Debug 模式下編譯沒問題, 換到 Release 模式就發生一堆問題.
典型的例子, 就是因為 c++ runtime library 設定不一样, 所形成的重複定義連結錯誤.
而另外一個常見的例子是 專案與 library 使用不一样的字元集合設定
(如: 一個用 Unicode Character Set, 另外一個用 Multi-Byte Character Set)
這個錯誤
發生缘由, 有多是
1. 你 link 的 lib 使用 C++ Multi-threaded DLL (/MD)
2. 而你的 source 使用的 C++ runtime library 是 Multi-threaded (/MT)
導致重複定義
解決方法:
兩個使用相同的 C++ runtime library.
例如都使用 static 的 Multi-threaded (/MT).
2. 错误 1 error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) 已经在 LIBCMT.lib(typinfo.obj) 中定义 MSVCRTD.lib
项目 -> 属性 -> c/C++ -> 代码生成 -> 运行时库 设置为: 多线程调试 DLL (/MDd)
被引用的库和调用的程序编译选项不一样,须要改为一致后编译
3. #pragma once与 #ifndef的区别
为了不同一个文件被include屡次
1 #ifndef方式
2 #pragma once方式
在可以支持这两种方式的编译器上,两者并无太大的区别,可是二者仍然仍是有一些细微的区别。
方式一:
#ifndef __SOMEFILE_H__
#define __SOMEFILE_H__
... ... // 一些声明语句
#endif
方式二:
#pragma once
... ... // 一些声明语句
#ifndef的方式依赖于宏名字不能冲突,这不光能够保证同一个文件不会被包含屡次,也能保证内容彻底相同的两个文件不会被不当心同时包含。固然,缺点就是若是不一样头文件的宏名不当心“撞车”,可能就会致使头文件明明存在,编译器却硬说找不到声明的情况
#pragma once则由编译器提供保证:同一个文件不会被包含屡次。注意这里所说的“同一个文件”是指物理上的一个文件,而不是指内容相同的两个文件。带来的好处是,你没必要再费劲想个宏名了,固然也就不会出现宏名碰撞引起的奇怪问题。对应的缺点就是若是某个头文件有多份拷贝,本方法不能保证他们不被重复包含。固然,相比宏名碰撞引起的“找不到声明”的问题,重复包含更容易被发现并修正。
方式一由语言支持因此移植性好,方式二 能够避免名字冲突
4. error LNK2019: 没法解析的外部符号 __imp__PathCombineW
PathCombine是Shell api须要引入库
#pragma comment( lib, "shlwapi.lib")
5. error C2662: "MyClass::GetName()”: 不能将“this”指针从“const MyClass”转换为“MyClass &”
bool MyClass::operator==(const MyClass* n1) const
{
return GetName() == n1->GetName();
}
缘由是不能在const函数中调用对象的非const方法,MyClass中的GetName()必须是const的。
6. template 模板
搞死了
模板声明和定义必须在同一个文件中,并且只有实例话模板类型时才编译模板实例
7. error C2275: “MyClass”: 将此类型用做表达式非法 MyClass.Instance();
缘由:Instance是静态方法,用.引用会出错。应该是MyClass::Instance()
8. error LNK2019: 没法解析的外部符号 "public: __thiscall MyClass(void)
缘由:只声明了构造函数,MyClass(); ,但未定义。 能够定义空函数,或者直接注释掉,使用默认构造函数。
9. error C2504: “testing”: 未定义基类
class PackToolTest : testing.Test {}
缘由:Test是testing命名空间下的一个类,须要用域操做符,testing::Test
还有一个问题,缺乏基类继承权限(public、protected、private)
10. error C2864: “MyClass::_nullpack”: 只有静态常量整型数据成员才能够在类中初始化
class MyClass {
string _nullpack = "test";
}
缘由:c++ 中,成员变量不能在声明时初始化,而是在构造函数初始化列表中先初始化
11. error LNK2019: 没法解析的外部符号 _WinMain@16 int main()
缘由:因为建立的是Win32 Project,和Win32 console Project的连接库不一样
方法1:在程序最开始的地方加上如下语句
#pragma comment(linker, "/subsystem:console ")
方法2:project > > setting > > 在link 的project options 中将/subsystem:windows(console)删了
12.相似“已经在 msvcprtd.lib(MSVCP80D.dll) 中定义”问题
vs2005 Debug /Release须要分别配制
分析一下错误来源,会发现:
1. 错误来源主要是重复定义的问题,并且重复定义的基本上都是VC Runtime和Standard C++ Library中的函数
2. LIBCMT和LIBCPMT为Release下的Lib,原本不该该出如今Debug版本的连接的Lib中
3. 重复定义的问题主要出如今:LIBCMT, LIBCPMT, MSVCPRTD, MSVCRTD
来看看出问题的LIB是那些:
1. LIBCMT:C Runtime库的多线程静态连接的Release版本
2. LIBCPMT:C++ Standard Library的多线程静态连接的Release版本
3. MSVCPRTD:C++ Standard Library的多线程DLL的Debug版本
4. MSVCRTD:C Runtime Library的多线程DLL的Debug版本
当前咱们的配置是多线程DLL的Debug版,所以3和4是应该出如今link的列表中的,不属于多余。然后二者则是只是当多线程静态连接Release 版中才会出现。这提示我在项目中加入的ANTLR.LIB多是形成这个问题的根源,由于静态库的编译选项很容易和主程序发生冲突,而且根据实际信息咱们 能够看出ANTLR.LIB应该是用多线程静态连接的Release版原本编译的。
解决方法:
一、首先查看编译项目依赖的其余项目的运行时库是否一致
二、若是不一致,改成一样的运行时库,如在下编译的是:“多线程调试 DLL (/MDd)”,如今须要把全部的依赖项目的运行时库都改成一致的库,就OK了。
13. error C2143: 语法错误 : 缺乏“;”(在“*”的前面)
缘由:产生错误处,某类型未include,可能头文件名拼写错误、头文件名已更改
14. error C2572: “MyClass::Invoke”: 重定义默认参数 : 参数 2
string MyClass::Invoke(const CParam& paraObj, INVOKETYPE type = ASYN)
缘由:默认参数,只需在声明时指定。方法定义的时候无需指定默认参数。
string MyClass::Invoke(const CParam& paraObj, INVOKETYPE type /*= ASYN*/)
{ ... }
15. 错误 C2558 没有可用的复制构造函数或复制构造函数声明为“explicit”
试图复制其复制构造函数为 private 的类。在大多数状况下,不该复制具备 private 复制构造函数的类。通用编程技术声明 private 复制构造函数以防止直接使用类。该类自己可能无用,或须要另外一个类才能正常工做。
尝试复制其复制构造函数为 explicit 的类。用 explicit 声明复制构造函数会阻止将类的对象传递到函数或从函数返回类的对象。
缘由: 拷贝构造函数、赋值函数参数必须用const修饰
16. 不能建立抽象类对象
缘由: 1. 存在虚函数未实现; 2. 因为疏忽重载虚函数格式错误(此问题须要仔细检查才能发现); 3. 虚函数名称与系统中已有的虚函数重名,致使重载失败(这点很纳闷)。
17. 没有找到MSCRV80D.dll
工程属性: 配置类型 由 exe 改为 lib 后生成, 而后再改回来
运行时会出现 “没有找到MSCRV80D.dll” 的异常
解决方法:
工程属性:MFC的使用 由 “使用标准Windows库” 改为 “在静态库中使用MFC“ 生成 ,而后再改回来
生成、运行 OK
18. CVTRES : fatal error CVT1100: 重复的资源。type:MANIFEST, name:1, language:0x0409
另外一个则提示为:
LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
已经到了连接期,应该说,问题就不像编译通不过那么别扭了,而查阅MSDN关于这两个问题的说明,终于找到了解决的方法,现简单的陈述以下:
首先,出现这两个问题的缘由都是一个,即文件中的现有资源文件和新资源字符串表 ID 冲突。微软也给出了解决这个问题的方法,可是,在现有的状况下,这个方法是靠不住的,由于,不可能不使用wx.rc资源。因此,一个变通的解决方法就是:
工程属性->配置属性-> 清单工具->输入和输出->嵌入清单,选择[否],便可。
19
1>c:\program files\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::wstring'
提示以上错误,则应该加上#include <string>头文件