VC++ 錯誤及解決方案錄

VC++ 錯誤及解決方案錄

 

 

error LNK2001: unresolved external symbol _main解決辦法

在編譯VC++6.0是,出現fatal error C1010: unexpected end of file while looking for precompiled header directive
的錯誤.

解決方法:

1、如果發生錯誤的文件是由其他的C代碼文件添加進入當前工程而引起的,則Alt+F7進入當前工程的 Settings,選擇C/C++選項卡,從Category組合框中選中Precompiled Headers,選擇Not Using Precompiled headers。確定。

2、在文件開頭添加:
#include "stdafx.h"

對預編譯頭文件說明如下:  
   
所謂頭文件預編譯,就是把一個工程(Project)中使用的一些MFC標準頭文件(如Windows.H、Afxwin.H)預先編譯,以後該工程編譯時,不再編譯這部分頭文件,僅僅使用預編譯的結果。這樣可以加快編譯速度,節省時間。  
   
預編譯頭文件通過編譯stdafx.cpp生成,以工程名命名,由於預編譯的頭文件的後綴是“pch”,所以編譯結果文件是projectname.pch。  
   
編譯器通過一個頭文件stdafx.h來使用預編譯頭文件。stdafx.h這個頭文件名是可以在project的編譯設置裏指定的。編譯器認爲,所有在指令#include   "stdafx.h"前的代碼都是預編譯的,它跳過#include   "stdafx.   h"指令,使用projectname.pch編譯這條指令之後的所有代碼。  
   
因此,所有的CPP實現文件第一條語句都是:#include   "stdafx.h"。   

 

 

 

 

 

 

 

 

 

2008-10-17:

 

error C2678: binary '<<' : no operator defined which takes a left-hand operand of type 'class ostream_withassign' (or there is no acceptable conversion)

 

解決辦法可能是.h和namespce std;衝突,選後者;

 

error C2079: 'file' uses undefined class 'std::basic_fstream<_Elem,_Traits>'

The fstream class is defined in the fstream header. Try adding a #include <fstream>.

http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/0b6174ad-bcfd-4863-b83f-bfd64a5f3620/

 

ios::app 與 iso:ate 的區別

 http://topic.csdn.net/t/20050103/21/3696236.html

fstream  能否作爲函數參數傳遞進去? (很簡單,fstream對象本身不可以拷貝,但用引用可以將其做爲參數傳遞給函數)

http://topic.csdn.net/t/20030215/11/1430571.html

C++ file and directory 刪除,移動,目錄瀏覽對話框,找某目錄下的所有文件(包括子目錄)

C++ Programmer's Cookbook

http://www.cppblog.com/mzty/archive/2006/01/12/2683.html

C++ Primer中文版(第4版) HTML 版

http://www.17xie.com/book-35806982.html

 

C++實現加減乘除

http://www.cppblog.com/jb8164/archive/2008/01/02/40211.html

 

rand() & srand() 清爽版:

http://zhidao.baidu.com/question/4856192.html

srand(time(0)); 的目的是使的每次產生的隨機數不同。如下:
#include "stdafx.h"
#include "time.h"
#include "stdlib.h"
#include "iostream.h"
int main(int argc, char* argv[])
{
for(int i=0;i<100;i++)
cout<<rand()<<'/t'<<endl;
return 0;
}
這裏沒有調用 srand 函數,你兩次運行程序看一下所產生的數是不是一樣,然後將 srand(time(0))加入到 for 的上面就不一樣了。
srand(time(0));
for(int i=0;i<100;i++)
cout<<rand()<<'/t'<<endl;
return 0;

C++文件讀寫操作(下面這篇講得清新易懂):

http://waicpp.blog.sohu.com/26485974.html

VS2005生成幫助文檔

http://blog.csdn.net/dreambroken/archive/2007/07/26/1709594.aspx

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章