锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
縐嶇被 钄瘋枃縐?
鍒悕 鏃?
浜у湴 涓浗銆佹棩鏈佸彴婀?
鑺辮壊 鑺辮壊闄や簡綺夌孩鑹層佺孩銆佺櫧銆侀粍浠ュ鏈夎澶氬彉鑹插搧縐嶏紝涔熸湁鏉傝壊鍝佺
鑺辨湡 鏄ユ湯鑷崇瀛?
鑺辮 緹庛佺埍銆佹亱錛?
鐜懓鏈韓浠h〃鐖辨儏錛岀櫧鑹茬殑浠h〃錛氭垜灝婃暚浣狅紱綰㈣壊鐨勪唬琛細鐑亱錛涚孩鐧芥販鍚堜唬琛細鍜岃В錛涢粍鑹茬殑浠h〃瀚夊
閲嶇偣 鎯呬漢鑺傞佽姳錛岀帿鐟版槸蹇呯劧涔嬮夛紝浣嗚娉ㄦ剰涓嶅悓棰滆壊浠h〃鐨勪笉鍚屾剰鎬濄?
鐜懓鑻辨枃鍚峳ose錛屾簮浜庡笇鑵婅rode錛岀孩鑹茬殑鎰忔濄傛硶鍥介潻鍛藉悗鏂扮敓鐨勮吹濡囦漢錛屾嬁鐮翠粦鐨勫瀛愮害鐟熻姮錛屽湪宸撮粠閮婂鐨勭帥灝旀閫婂畢閭稿緩閫犱簡涓搴у畯浼熺殑鐜懓鍥紝騫跺懡浜哄埌嬈ф床鍙婁笘鐣屽悇鍦版悳闆嗙弽璐電殑鐜懓鍝佺錛涙嵁璇村湪濂圭殑鐜懓鍥噷縐嶆鐫涓変竾鏍帿鐟幫紝鑰屽ス鐨勮姳鍖犱篃鏄彶涓婄涓涓皾璇曚互浜哄伐鍩圭帿鐟拌姳縐嶇殑浜猴紝鎷滃ス涔嬭祼錛岀帿鐟拌繘鍏ヤ簡銆岃繎浠c嶃傜害鐟熻姮璇風敾瀹墮瞾閬撶壒綰綍鐜懓鍥噷鐜懓鐨勫Э鎬侊紝浣嗘槸鏈強瀹屾垚錛岀編浜哄嵈宸查娑堢帀孌掋傚叾鍚庨瞾閬撶壒鐨勭敾浠ャ庣帿鐟板浘璋便忓嚭鐗堟垚鍐岋紝鍥犺岃幏寰椼庣帿鐟扮敾瀹躲忕殑緹庡悕銆傞瞾閬撶壒綰ょ粏銆佷紭闆呯敾椋庯紝浼間箮姘歌繙姝岄鐫鐨囧綰︾憻鑺湭瀹屾垚鐨勬ⅵ錛屾瓕棰?nbsp; 闃呰鍏ㄦ枃
]]>
]]>
]]>
鍘熸枃錛欳++鐨勪竴浜涘厤璐瑰簱
//鏁寸悊 by RobinKin (鐜嬩寒)
闃呰鍏ㄦ枃
]]>
浠婂ぉ鎵句簡涓悊鐢憋紝鍚冨畬鍗堥キ灝變粠瀹為獙瀹ゆ簻鍥炴潵浜?br>鍥炴潵鏈潵鎯崇戶緇啓紼嬪簭
鎹i紦浜嗕竴浼?br>鎾戜笉涓嬪幓
涓婂簥浜?br>韜轟簡涓涓灝忔椂錛屽眳鐒跺仛浜嗕笁涓ⅵ........濂囨殑姊?...
璁板緱姣旇緝娓呮鐨勪竴涓槸涓涓笉璁よ瘑鐨勫笀鍏勬嬁浜嗕竴鏈珻璇█×××榪欑被鐨勪功錛屽緢鏃э紝鍙垜鐪嬶紝鐒跺悗榪樼粰鎴戞紨紺轟簡涓涓鐞嗘暟鎹殑紼嬪簭鍚庢潵鎴戞帴浜嗕釜鐢?shù)璇濆Q屼粬灝變笉璁蹭簡.....
]]>
涓嶈繃甯堝鑻辮澶熺墰
榪欐槸涓嬭澆鍦板潃
http://www.jollybear.com/bigcityadventuresf/index.html
======================
鍥炲鏍″悗灞呯劧鐜╄繖涓父鎴忓埌鍗佷簩鐐瑰
涓嬭澆婧愪唬鐮?/font>
鍘熸枃鍑哄錛?a target=_blank>How to Use <fstream> Classes for File I/O
鎽樿錛?/strong>浼犵粺鐨勬枃浠?I/O 搴撳 Unix 鐨?<io.h> 鍜?<stdio.h> 錛岀敱浜庡叾紼嬪簭鎺ュ彛鐨勫師鍥狅紝鍦ㄥ緢澶х▼搴︿笂寮哄埗紼嬪簭鍛樿繘琛屾煇浜涘鐞嗭紝緙轟箯綾誨瀷瀹夊叏鍜屽浗闄呭寲鏀寔銆侰++ 鐨?<fstream> 搴撳垯鍦ㄦ枃浠剁殑 I/O 鏂歸潰鎻愪緵浜嗕竴涓寮虹殑銆侀潰鍚戝璞$殑銆佸叿鏈夊浗闄呭寲鎰忚瘑鐨勫簱銆傛湰鏂囧皢浠嬬粛濡備綍浣跨敤榪欎釜搴撹繘琛屾枃浠剁殑 I/O 澶勭悊騫跺埄鐢ㄥ畠鏉ョ紪鍐欐槗浜庤法騫沖彴鐨勪唬鐮併?/td> |
銆銆澶у鏁?C++ 紼嬪簭鍛橀兘鐔熸?zhèn)変笉姝竴涓枃浠?I/O 搴撱傞鍏堟槸浼犵粺鐨?Unix 椋庢牸鐨勫簱錛屽畠鐢變竴浜涗綆綰у嚱鏁板 read() 鍜?open()緇勬垚銆傚叾嬈℃槸 ANSI C 鐨?<stdio.h> 搴擄紝瀹冨寘鍚?fopen() 鍜?fread()絳夊嚱鏁般傚叾瀹冪殑榪樻湁涓浜涘叿澶囨墍鏈夋潈鐨勫簱鎴栨鏋訛紝姣斿 MFC錛屽畠鏈夊緢澶氳嚜宸辯殑鏂囦歡澶勭悊綾匯?br>銆銆榪欎簺搴撲竴鑸兘寰堥毦璺ㄥ鉤鍙頒嬌鐢ㄣ傛洿緋熺殑鏄紝涓婅堪鎻愬埌鐨?C 搴撶敱浜庡叾紼嬪簭鎺ュ彛鐨勫師鍥狅紝鍦ㄥ緢澶х▼搴︿笂寮哄埗紼嬪簭鍛樿繘琛屾煇浜涘鐞嗭紝鑰屼笖緙轟箯綾誨瀷瀹夊叏鏀寔銆?br>銆銆鏍囧噯 C++ 鎻愪緵鎻愪緵浜嗕竴涓寮虹殑銆侀潰鍚戝璞$殑銆佸叿鏈夊浗闄呭寲鎰忚瘑鐨?nbsp; <fstream> 搴撱傝繖涓簱鍖呭惈涓緋誨垪媧劇敓浜庢爣鍑?ios_base 鍜?ios 綾葷殑綾繪ā鏉褲傚洜姝わ紝 <fstream> 鎻愪緵浜嗛珮綰х殑鑷姩鎺у埗鏈哄埗鍜屽仴澹с傛湰鏂囦笅闈㈠皢紺鴻寖濡備綍浣跨敤 <fstream> 綾誨疄鐜版枃浠剁殑杈撳叆/杈撳嚭澶勭悊錛?br>
絎竴姝ワ細鍒涘緩鏂囦歡嫻?br>銆銆杈撳叆鏂囦歡嫻侊紙ifstream錛夋敮鎸侀噸杞界殑 >> 鎿嶄綔絎︼紝鍚屾牱錛岃緭鍑烘枃浠舵祦錛坥fstream錛夋敮鎸侀噸杞界殑 << 鎿嶄綔絎︺傜粨鍚堜簡杈撳叆鍜岃緭鍑虹殑鏂囦歡嫻佽縐頒負 fstream銆備笅闈㈢殑紼嬪簭鍒涘緩浜嗕竴涓?ifstream 瀵硅薄錛歞ict錛屽茍灝嗚瀵硅薄涓殑姣忎竴涓崟瀛楁樉紺哄埌灞忓箷涓婏細
#include <iostream> #include <string> #include <fstream> #include <cstdlib> using namespace std; int main() { string s; cout<<"enter dictionary file: "; cin>>s; ifstream dict (s.c_str()); if (!dictionary) // were there any errors on opening? exit(-1); while (dictionary >> s) cout << s <<''\n''; }銆銆鎴戜滑蹇呴』璋冪敤 string::c_str() 鎴愬憳鍑芥暟錛屽洜涓?fstream 瀵硅薄鍙帴鍙楀父閲忓瓧絎︿覆浣滀負鏂囦歡鍚嶃傚綋浣犲皢鏂囦歡鍚嶄綔涓哄弬鏁頒紶閫掓椂錛屾瀯閫犲嚱鏁拌瘯鍥炬墦寮鎸囧畾鐨勬枃浠躲傛帴鐫錛屾垜浠敤閲嶈澆鐨?錛佹搷浣滅鏉ユ鏌ユ枃浠剁殑鐘舵併傚鏋滃嚭閿欙紝璇ユ搷浣滅浼板間負 true銆傛渶鍚庝竴琛屾槸涓驚鐜紝姣忔鍙嶅閮戒粠鏂囦歡璇誨彇涓涓崟瀛楋紝灝嗗畠鎷瘋礉鍒?s錛岀劧鍚庢樉紺哄嚭鏉ャ傛敞鎰忔垜浠笉蹇呮樉寮忓湴媯鏌?EOF錛屽洜涓洪噸杞芥搷浣滅 >> 浼氳嚜鍔ㄥ鐞嗐傛澶栵紝鎴戜滑涓嶇敤鏄懼紡鍦板叧闂鏂囦歡錛屽洜涓烘瀽鏋勫嚱鏁頒細涓烘垜浠仛榪欎歡浜嬫儏銆?br>銆銆榪囨椂鍜岃崚搴熺殑 <fstream.h> 搴撴敮鎸?ios::nocreate 鍜?ios::noreplace 鏍囧織銆備絾鏂扮殑 <fstream> 搴撳凡緇忓彇浠d簡 <fstream.h> 騫朵笉鍐嶆敮鎸佽繖涓や釜鏍囧織銆?br>
ios::app // 浠庡悗闈㈡坊鍔? ios::ate // 鎵撳紑騫舵壘鍒版枃浠跺熬 ios::binary // 浜岃繘鍒舵ā寮?I/O (涓庢枃鏈ā寮忕浉瀵? ios::in // 鍙鎵撳紑 ios::out // 鍐欐墦寮 ios::trunc // 灝嗘枃浠舵埅涓?0 闀垮害
浣犲彲浠ョ敤浣嶅煙鎿嶄綔絎?OR 緇勫悎榪欎簺鏍囧織錛?/p>
ofstream logfile("login.dat", ios::binary | ios::app);
fstream 綾誨瀷瀵硅薄鍚屾椂鏀寔璇誨拰鍐欐搷浣滐細
fstream logfile("database.dat", ios::in | ios::out);
絎簩姝ワ細璁劇疆鏂囦歡鐨勪綅緗?br>銆銆鏂囦歡鍏峰涓涓昏緫鎸囬拡錛屽畠鎸囧悜璇ユ枃浠朵腑鐨勬煇涓亸縐諱綅緗備綘鍙互閫氳繃璋冪敤seekp()鎴愬憳鍑芥暟錛屼互瀛楄妭涓哄崟浣嶅皢榪欎釜鎸囬拡瀹氫綅鍒版枃浠剁殑浠繪剰浣嶇疆銆備負浜嗚幏鍙栦粠鏂囦歡寮濮嬪鍒板綋鍓嶅亸縐葷殑瀛楄妭鏁幫紝璋冪敤seekp()鍗沖彲銆傚湪涓嬮潰鐨勪緥瀛愪腑錛岀▼搴忓皢鏂囦歡浣嶇疆鍓嶇Щ10涓瓧鑺傦紝鐒跺悗璋冪敤 tellp()鎶ュ憡鏂頒綅緗細
ofstream fout("parts.txt"); fout.seekp(10); // 浠?鍋忕Щ寮濮嬪墠榪?10 涓瓧鑺? cout<<"new position: "<<fout.tellp(); // 鏄劇ず 10
浣犲彲浠ョ敤涓嬮潰鐨勫父閲忛噸鏂板畾浣嶆枃ian鎸囬拡錛?
ios::beg // 鏂囦歡寮濮嬩綅緗? ios::cur // 褰撳墠浣嶇疆錛屼緥濡? ios::cur+5 ios::end // 鏂囦歡灝?/pre>絎笁姝ワ細璇誨啓鏁版嵁
銆銆fstream 綾諱負鎵鏈夊唴寤烘暟鎹被鍨嬩互鍙?std::string 鍜?std::complex 綾誨瀷閲嶈澆 << 鍜?>> 鎿嶄綔絎︺備笅闈㈢殑渚嬪瓙紺鴻寖浜嗚繖浜涙搷浣滅鐨勪嬌鐢ㄦ柟娉曪細fstream logfile("log.dat"); logfile<<time(0)<<"danny"<<''\n''; // 鍐欎竴鏉℃柊璁板綍 logfile.seekp(ios::beg); // 浣嶇疆閲嶇疆 logfile>>login>>user; // 璇誨彇浠ュ墠鍐欏叆鐨勫?/pre>
浣滆呯畝浠?/strong>
銆銆Danny Kalev 鏄竴鍚嶉氳繃璁よ瘉鐨勭郴緇熷垎鏋愬笀鍜岃蔣浠跺伐紼嬪笀錛屼笓鏀?C++ 鍜屽艦寮忚璦鐞嗚銆?997 騫村埌 2000 騫存湡闂達紝浠栨槸 C++ 鏍囧噯濮斿憳浼氭垚鍛樸傛渶榪戜粬浠ヤ紭寮傛垚緇╁畬鎴愪簡浠栧湪鏅氳璦瀛︾爺絀舵柟闈㈢殑紜曞+璁烘枃銆?涓氫綑鏃墮棿浠栧枩嬈㈠惉鍙ゅ吀闊充箰錛岄槄璇葷淮澶氬埄浜氭椂鏈熺殑鏂囧浣滃搧錛岀爺絀?Hittite銆丅asque 鍜?Irish Gaelic 榪欐牱鐨勮嚜鐒惰璦銆傚叾瀹冨叴瓚e寘鎷冨彜鍜屽湴鐞嗐侱anny 鏃跺父鍒頒竴浜?C++ 璁哄潧騫跺畾鏈熶負涓嶅悓鐨?C++ 緗戠珯鍜屾潅蹇楁挵鍐欐枃绔犮備粬榪樺湪鏁欒偛鏈烘瀯璁叉巿紼嬪簭璁捐璇█鍜屽簲鐢ㄨ璦璇劇▼銆?br>
]]>
This page contains a listing of "difficult to diagnose" error messages and possible fixes. I haven't taught a programming class that uses Visual C++ in several years so this list is probably out of date by now. It was valid for Microsoft Visual C++ version 6.0 service pack 3.
C1001: INTERNAL COMPILER ERROR (compiler file 'msc1.cpp', line 1786) Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information
This error results from leaving off the parentheses immediately following the function name in a function header. To correct the error simply add () to the end of the function name.
C1010: unexpected end of file while looking for precompiled header directive
If your project is an MFC AppWizard created project then this error results from not #including StdAfx.h as the first 錛?span lang=EN-US>include statement (before any other 錛?span lang=EN-US>includes, data declarations, or executable program code).
C1083: Cannot open precompiled header file: 'Debug/<Project-Name>.pch': No such file or directory
This error results from a missing file - the compiled version of StdAfx.cpp. Visual C++ does a poor job of keeping track of this file and frequently "forgets" how to build it. This problem often occurs after restoring a saved workspace from diskette without the Debug directory. To fix the error select StdAfx.cpp from the workspace file list them choose Compile from the Build menu. If that doesn't work the go to Project -> Settings, select the C/C++ tab, and click the radio button labeled Create Precompiled Headers.
C2001: newline in constant
This error is usually caused by a string or character constant that is missing its closing ' or " symbol.
C2065: '<data-member name>' : undeclared identifier
If this error occurs in one of your member functions then it is generally the result of forgetting the class scope operator in front of the function name in your .cpp file.
C2143: syntax error : missing ';' before 'PCH creation point'
Check each of the 錛?span lang=EN-US>include files to ensure that the closing brace of each class declaration is followed by a semicolon.
C2143: syntax error : missing ';' before '*'
If this error is followed by two C2501 errors then the problem is an undeclared class name within a pointer declaration.
For example, the declaration:
CClass *pObject;
will generate the above error message followed by a C2501 error message for 'CClass' and another C2501 message for 'pObject'. The problem is that the compiler isn't recognizing CClass as a valid class/type name. To correct the problem add a 錛?span lang=EN-US>i nclude of the file containing the declaration of CClass (e.g., 錛?span lang=EN-US>i nclude CClass.h)
C2447: missing function header (old-style formal list?)
This error usually results from a missing { or use of a ; instead of a { following the parameter list of a function header.
C2511: '<function-name>' : overloaded member function not found in '<class-name>'
This error results from a mismatch in the parameter list of a member function declaration (.h file) and definition (.ccp file). Check the forward declaration of the function in the .h file and its definition in the .cpp file and ensure that the number of parameters and the type of each parameter match exactly.
C2512: '<constructor-function-name>' : no appropriate default constructor available
This error usually occurs when you implement the constructor function of a derived class and forget to include parameter passing to the base class constructor function. For example assume that CDerived is derived from CBase and that the CBase constructor function requires one parameter (e.g., int A). If you define the CDerived constructor function as:
CDerived::CDerived(int A, int B) { ... }
the compiler will issue the above error message on the line containing the function header of CDerived::CDerived() because you haven't provided instructions for routing the parameter A to CBase::CBase(). Because you didn't provide instructions the compiler assumes that CBase::CBase() requires no arguments and it complains because no version of CBase::CBase() has been defined that accepts zero arguments.
If you intended to provide a version of CBase::CBase() that requires no arguments then the error message indicates that you forgot to declare that function in your base class declaration (e.g., in CBase.h).
If CBase::CBase() does require one or more arguments then you must correct the problem by including explicit instructions for passing parameters from the derived class constructor function to the base class constructor function. The correction for the example above is:
CDerived::CDerived(int A, int B) : CBase(A) { ... }
C2556: '<function-name>' : overloaded functions only differ by return type
C2371: '<function-name>' : redefinition; different basic types
These errors usually result from a mismatch of function type between a .h and .cpp file. Check the forward declaration of the function in the .h file and its definition in the .cpp file and make the function return type identical in both files.
C2601: '<function-name>' : local function definitions are illegal
This error results from defining one function inside the body of another function. It usually means that you omitted one or more } symbols in the function just before the function named in the error message.
C2653: '<Class-Name>' : is not a class or namespace name
This error usually results from not having 錛?span lang=EN-US>include "StdAfx.h" as the first 錛?span lang=EN-US>include statement in your class.cpp file. It can also occur if your class definition is in a .h file and you forget to 錛?span lang=EN-US>include that .h file in another file that refers to the class name.
C2661: '<Class-Name>::<Function-Name>' : no overloaded function takes n parameters
This error indicates a mismatch between the parameters used in a function call (e.g., from main.cpp) and the declaration of the function. The function call is passing n parameters and there is no function declaration that uses that number of parameters.
LNK1104: Cannot open file nafxcwd.lib
This error sometimes occurs when a project uses a class from the MFC but the project settings don't explicitly tell the link editor to look in the MFC libraries.
Go to Project --> Settings (Build --> Settings in Visual C++ 4.0). On the General tab check the box that says "Use MFC in a Shared DLL".
LNK1168: cannot open Debug\<Project-Name>.exe for writing
This error occurs when the link editor attempts to write to a .exe file that is currently in use. The .exe file of an executing program is write protected until the program is terminated. Look at the status bar at the bottom of your screen and find the icon representing your executable application. Open the application and exit from it. Then select Build.
LNK2001: unresolved external symbol __endthreadex
LNK2001: unresolved external symbol __beginthreadex
These errors result from using an MFC object or function without telling the link editor to search the MFC libraries.
Go to Project --> Settings (Build --> Settings in Visual C++ 4.0). On the General tab check the box that says "Use MFC in a Shared DLL".
LNK2001: unresolved external symbol _main
Your project doesn't contain a function called main(). The error usually results from forgeting to add main.cpp to the project workspace.
<File>.obj : error LNK2001: unresolved external symbol "public: void __thiscall <Class1>::<Function1>(<Type>)"
This a generic form of a LNK2001 error where <File>.obj can be any object file in your project and <Class1>::<Function1>(<Type>) can be any function in any class. Substitute the specific <File>, <Class>, <Function>, and <Type> in your message into the instructions below to diagnose and correct the problem.
An LNK2001 error means that the link editor is looking for a compiled function and can't find it. The call to the "missing function" is somewhere in <File>.cpp. Unfortunately, double-clicking on the error message won't take you to the point in <File.cpp> where the function is called but you can search for it with Find or Find In Files. The function the link editor can't find is a member of <Class>, its name is <Function1>, and its return type is <Type>.
There are two common reasons for a LNK2001 error:
1. The call in <File>.cpp doesn't match the function prototype in <Class>.h and/or the implementation in <Class>.cpp. The mismatch may be in the function name, return type, or number and/or type of parameters. Correction strategies include:
o Check that the function name is spelled the same (case sensitive) in all three files (File.cpp, Class.h, and Class.cpp).
o Check that the function is actually declared and defined within <Class> - perhaps you defined it as a member of a different class or perhaps you tried to call the function (in <File>.cpp) using an object or object pointer of a different class.
o Check that the number and type of parameters in the function implementation (in <Class>.cpp) matches the number and type of parameters declared in the function declaration in <Class>.h.
o Check that the number and type of parameters in the function call (in <File>.cpp) matches the number and type of parameters declared in the function header in <Class>.cpp.
2. The function was never declared or was declared but never defined. To see if either is the case go to the ClassView window of the Workspace view. Click the + next to <Class> and find <Function> in the list of member functions.
o If <Function> is NOT in the list then it was never declared or defined - add a declaration to the class declaraion in <Class>.h and implement the function in <Class>.cpp.
If <Function> is in the list then right click on it and select Go To Definition from the pop-up menu. If you get the error message Cannot find definition (implementation) of this function then the function was declared but never defined (implemented). Implement the function to
o <Class>.cpp.
LNK2005: <some-long-string-of-mostly-garbage> already defined in <name>.lib(<name>.obj)
This error usually results from including a source code file multiple times. If you recognize any of the names in the message then it probably results from multiple inclusion of one of your own header files. Check to be sure that you've used #ifndef/#define/#endif properly your header files. If you don't recognize the name then it's probably multiple inclusion of a system file (e.g., afxwin.h). Make sure that you haven't explicitly included something in main.cpp that is already included in one of your own header files. Also check that you haven't 錛?/span>included a .cpp file where you should have 錛?/span>included a .h file