http:^^www.cs.wisc.edu^~cs302^faq.html
来自「This data set contains WWW-pages collect」· HTML 代码 · 共 530 行 · 第 1/2 页
HTML
530 行
Date: Tue, 05 Nov 1996 00:33:19 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Wed, 28 Aug 1996 05:46:10 GMTContent-length: 19759<HTML><HEAD><TITLE>CS 302 Frequently Asked Questions (FAQ)</TITLE></HEAD><BODY><H1 ALIGN=CENTER>CS 302 Frequently Asked Questions (FAQ)</H1>This FAQ came about because of problems that many students were encountering.It is not comprehensive, and it will probably be constantly evolving.It is grouped by which language is being used, and there is a list of non-language-specific problems at the end. If you don't find what you want here,ask a consultant. If you are a consultant, you can e-mail me at <EM><!WA0><A HREF="http://www.cs.wisc.edu/~cs302/email.html">perkinst@cs.wisc.edu</A></EM>.<UL><LI> <!WA1><A HREF="#C++QUESTIONS"> C++ Common Problems: </A> Using the Borland IDE and the C++ Language </LI><ul><li> <!WA2><a href="#Compiler_Linker_Errors"> Compiler and Linker Errors </a> : When Borlandrefuses to run your program. </li><li> <!WA3><a href="#Runtime_Errors"> Runtime Errors</a> : Crashes, floating point errors,protection faults -- errors that occur while your program is running. </li><li> <!WA4><a href="#IDE_Errors"> Borland IDE problems </a>: Difficulties with your programfiles or project files, windows, the screen editor. In general, problems with the mechanics of using the Borland IDE. </li><li> <!WA5><a href="#IO_Errors"> Input/Output Errors </a>: Problems with reading in input, sending output to files, etc. </li><li> <!WA6><a href="#Frustration"> It's just not working!! </a> </li></ul><LI> <!WA7><A HREF="#FORTRAN"> A FORTRAN hint: </A> How to write and run programs efficiently</LI><LI> <!WA8><A HREF="#MISC"> Miscellaneous Problems: </A> Printing, E-mail, Disk Quotas... </LI></UL><HR><A NAME="C++QUESTIONS"><H2 ALIGN=CENTER>C++</H2><a name="Compiler_Linker_Errors"><h2> Compiler and Linker Errors </h2><ul><LI><B>Error: Statement missing ;</B> <BR> <BR> Fix: Click on this message, and will get the highlighted line in yoursource file. This line or the line immediately before it is not endedwith a ; (semicolon). All lines of <B>C</B> code except statementswhich can be followed by compound statements ( <B>if</B> ,<B>else</B>, <B>do</B>, etc.) should have a ; to mark the end of thestatement. </LI> <BR> <BR><LI><B>Error: Declaration syntax error</B><BR><BR>Fix: If this line isn't declaring a variable, then the problemis definitely that some variable declaration immediately before it ismissing a ; (semicolon). Otherwise, this may still be the problem,but you may have also done something else like missed a , (comma) inbetween variable names, or put a space in a variable name. (variablesmust be one word)</LI> <BR><BR><LI><B>Error: Unable to assign char* to char</B><BR><BR>Fix: A char variable is a single keystroke like 's' or'\n'. (note the single quotes) A char* variable is an array ofcharacters (a string) like "hello there!" (note the double quotes).For beginner's purposes, view them as entirely different animals. Inparticular, 's' is not the same as "s". ('s' takes up 1 byte ofmemory whereas "s" is stored as a byte containing 's' followed by abyte containing the end of string message.)</LI><BR><BR><LI><B> The program seemed to be (nearly) working before, but now it gets all sorts of errors involving i/ostreams when I run it. </B> <BR> <BR>It is linking the program without compiling the source code. Click inside the .cpp window, and select Project,Compile. Then try runningit again.</LI><LI><STRONG>Why do I get that annoying "linker error in OwlMain"?</STRONG><BR><BR>Chances are that you have not created/opened a project. You must do thisthrough the Project menu...you cannot do it through the File menu. Once youhave created/opened a project, make sure that you choose the Build All optionunder the Project menu. If you don't, chances are that you will get many morelinker errors.<BR><BR></LI><LI><STRONG>My program source file has a ".c" extension and the Borland compilercomplains when I attempt to compile it. How do I make it a C++ file?</STRONG><BR><BR>This is caused by forgetting to choose the "Advanced" option when creating aproject file. The easiest way to fix this problem is to select the sourcecode file name in the project window (you will know it is selected because itwill be highlighted). Press the right mouse button and a menu will pop up.Choose "Edit Node Attributes" from this menu. It will produce a window thatwill allow you to change the default extension for the file...choose ".cpp".If you have saved the program source file with the ".c" extension, you will want to resave the file with a ".cpp" extension. Use the "Save As" optionunder the "File" menu.<BR><BR></LI></ul><a name="Runtime_Errors"><h2> Run-time Errors </h2><ul><LI><STRONG>My program gives me some weird Windows error message when I run it.What can I do?</STRONG></li><BR><BR>Unfortunately, this is a very wide open problem and can be caused by numerousthings. Common problems are the following: trying to use a pointer thatpoints to NULL, accessing elements beyond the bounds of an array, creatinglarge data structures (like 2-dimensional integer arrays) as local variablesto functions, running out of disk space, etc. Unfortunately, some of theseproblems don't exhibit consistent behavior, but most times you can use theinteractive debugger to figure out what the problem is.<BR><BR></LI><LI><strong>My program starts to run, but then it stops, and I get awindow that tells me "General Protection Exception".</strong><br><br>This error is caused by access memory outside of legal bounds for yourprogram. If often means you used an array, and tried to access or setelements outside of the array bounds. For instance, if you have anarray X[10], you may have asked for X[-2] or X[14]. Another possiblecause for this error is that you are using pointers, and you attemptedto access a pointer that had not yet been initialized. To find such anerror, it is often easiest to use the debugger to trace down the line ofcode that causes the memory error.<br><br></li><li> <strong> While the programming is running I get a "floating pointunderflow" or "floating point:division by zero", and the program stops. </strong> <p>A floating point underflow can be caused by uninitialized variables. Ifyou declare some floats or doubles and don't set them to some value beforeyou use them, they may start out with huge or tiny values that cause errorsin calculations. The simple fix is to initialize all your floats to zero. <p>A division by zero error may not be obvious to look at the code, but canoccur when variables have unexpected values. Often you will be performingsome calculation inside a loop, and the loop goes one place too far or thevery first or very last iterations form special cases, resulting in a division by zero. Unless you can spot it right away, the best way to findsuch an error is probably to use the debugger to track down the offendingline of code. Then you can run the program again anduse the <b>watch</b> feature to view the variables involved, and see what causesthings to run afoul. <br><br></li></ul><a name="IDE_Errors"><h2> Borland IDE Errors </h2><ul><LI><STRONG>Why do I see nothing when I open a project?</STRONG><BR><BR>If you open an existing project and all you see is the background of theBorland IDE, choose the Project option under the View menu. This will showyou the project window.<BR><BR></LI><LI><STRONG>Why is there nothing in my project window?</STRONG><BR><BR>Good question...could be an accidental thing or a fluke. The way to fix thisis to select the Target option under the Project menu. The easy thing to dois to use the same name as the project (minus the .ide extension). Then yougo through the same process as creating a project.<BR><BR></LI><LI><STRONG>When I try to open my program file (.cpp extension), I get some weird message about truncating lines. What's up with that?</STRONG><BR><BR>Another good question...more than likely, you named your project with a ".cpp"extension. The default extension for a project file is ".ide" and should beleft this way. Unfortunately, it is questionable if you will be able to getyour source program back. Ask a consultant to attempt to salvage your codefrom network backups.<BR><BR></LI><LI><STRONG>My program source file has a ".c" extension and the Borland compilercomplains when I attempt to compile it. How do I make it a C++ file?</STRONG><BR><BR>This is caused by forgetting to choose the "Advanced" option when creating aproject file. The easiest way to fix this problem is to select the sourcecode file name in the project window (you will know it is selected because itwill be highlighted). Press the right mouse button and a menu will pop up.Choose "Edit Node Attributes" from this menu. It will produce a window thatwill allow you to change the default extension for the file...choose ".cpp".If you have saved the program source file with the ".c" extension, you will want to resave the file with a ".cpp" extension. Use the "Save As" optionunder the "File" menu.<BR><BR></LI><LI><STRONG>Borland C++ always crashes when I attempt to run it. How can I fixthis?</STRONG><BR><BR>I would recommend that you ask a consultant to do this. There are Borlandconfiguration files that have apparently been corrupted.<BR><BR></LI></ul><a name="IO_Errors"><h2> Input/Output Errors </h2><ul><li><strong>I'm trying to do a "cin.getline", but it's not working. When Irun the program, it just goes right by the getline as if it weren't there.</strong><p>This is a very common problem. There can be problems when you mix "cin >>"and "cin.getline" input statements in a program. The "cin >>" function willtake input, but it leaves a newline character in the input buffer. If agetline call follow a "cin >>", then the getline will read this single newlinecharacter and stop. It will appear as if the getline read nothing at all.So whenever you have a getline following a "cin >>" you must clear thenewline character from the buffer either with a "cin.ignore" or another"cin.getline". This should, of course, be placed between the "cin >>" and
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?