How to run C ++ STL programs

xiaoxiao2021-03-06  53

Author: dawn (Morning) Keywords: C STL source: original [statement] For copy, distribute, please attach this statement, thank you. Original: http://morningspace.51.net/, MOYINGZZ@etang.com This article extracts self-writer self-writer "C STL easy guidance", and briefly introduces some details of running a STL program in a specific C compiler environment. And provide some solutions that may encounter problems, suitable for C fans reading of STL programs yet. This is selected as an example of Microsoft Visual C 6.0 and Borland C Builder 6.0 currently under Windows platform. Although Visual C 6.0 is not very good for the latest ANSI / ISO C standards. However, Visual C .NET (that is, VC7.0) has improved in this regard. You can use a variety of ways to run a STL program, such as under Visual C , you can compile running directly in the DOS command line, or you can use the console application in the VC IDE. The situation is similar to C Builder. For Visual C , if you are in the DOS command line, you first need to find its compiler. Assuming your Visual C is under C: / Program Files / Microsoft Visual Studio / VC98, the path where its compiler should be C: / Program Files / Microsoft Visual Studio / VC98 / BIN, where you can find Cl.exe file. Please add / gx and / mt parameters when compiling. If everything is normal, the result will generate an executable. As shown below: CL / GX / MT First_STL_PRG.CPP The former parameters are used to inform the compiler to allow exception handling. The abnormality processing mechanism (ie Try ... throw ... catch syntax) is used in the PJ Plauger STL, so this parameter should be added, otherwise there will be the following warning information: Warning C4530: C Exception Handler Used, But Unwind Semantics Are Not Enabled. The latter parameter is used to support the program to support multithreading, which requires the libcmt.lib library file when link. However, P. J. Plauger STL is not a thread safe (Thread Safety). If you use STL implementations like Stlport in a VC environment, you need to add this parameter because stlport is a thread. If you can choose a console application when you create a new project in an IDE environment. As for the settings of those parameters, they can be done by setting compilation options in the settings feature in the Project function menu item [ALT F7].

Sometimes, when compiling STL programs in the IDE environment, the following warning may occur: Warning C4786: '...': Identifier Was Truncated to '255' Characters in The Debug Information This is because the compiler compiles in the debug state, The identifier length that appears in the program is limited to 255 characters. If the maximum length is exceeded, these identifiers cannot be viewed and calculated during the debug phase. In a large number of template functions and template classes in the STL program, the compiler When instanting these content, the identifier generated after expanding is long (there will be more than 1,000 characters!). If you want to know this Warning, it is very simple. In the program, add the following line code: Vector string_array; // Similar to the string array variable for such Warning, of course, can be set, but there is also a solution. You can join the following line at the beginning of the file: #pragma Warning (Disable: 4786). It enforces the compiler to ignore this warning message, which is a bit rude, but it is very effective. As for C Builder, the operation mode in its DOS command line is like this. If your C Builder is installed in C: / Program Files / Borland / CBuilder6. The path where its compiler is located should be C: / Program files / borland / cbuilder6 / bin, where you can find the BCC32.exe file, enter the following command, that is, the BCC32 EXAMPLE2_2.CPP is in the IDE environment, When you create a new application, select Console Wizard. Now you can run the previous sample program on your machine. However, please don't have a lot of mouth, some details have to be invited to pay attention. Caution the compiler to leave the trap. Please see the following code: typedef vector int_vector; typef back_insert_iterator back_ins_iTR; please pay attention to ">" The front of the front of the front, it is best not to save. If you regret the disk space occupied by this space, it is too disappointing. The reason is still the defect of the C compiler itself. The above code is equivalent to the following code (the compiler is also the translation work): typedef back_insert_Iterator > back_ins_iTR; if you don't have a splings, the compiler will put ">>" mistakenly think is a single one Identification (looks like that data stream input operator ">>"). In order to avoid this problem, C requires the user to insert space between two right polarizers. So, you are best to do this, to avoid unnecessary trouble. But interesting is that the code before the above line is expanded, even if you don't have a splitter, the compiler is not reported in Visual C . The same code is not so lucky in C Builder.

However, it is best not to be lucky. If you use the way of writing after the development, both compilers will not give you a love. Ok, please forgive my swap, now you can feel the truly unique charm of the STL, I wish you good luck! Note: This article has been posted on 9CBS, view related comments, please hereby: http://morningspace.51.net/Document/computer/Plhowtorunstl.xml

转载请注明原文地址:https://www.9cbs.com/read-116484.html

New Post(0)