Exploring flexible C/C ++ language commands

Source: Internet
Author: User

The flexibility of C/C ++ is based on its complex syntax. Therefore, it is very likely that beginners will be discouraged. If they stick to it, they will find that, it's easy to look at C # and Java syntaxes. I hope this article will teach you more.

In the VIM Editor Environment, You can compile the program by using the ": make" make tool, which has been described in several articles of cloud wind mentioned in my article yesterday, of course, the premise is that there is a Makefile file in the current directory. After running ": make.

If there is an error in the program, it will be displayed. At this time, the cursor will automatically point to the first place where an error occurs, and you can also see the error prompt. Then, you can correct the error, instead of finding the line with the error. Remember the following useful commands:

 
 
  1. # Include
  2. # Include
  3. # Include
  4. Int main (){
  5. Using namespace std;
  6. Ostringstream strbuf;
  7. /* Write a string */
  8. IntLucky=7;
  9. FloatPi=3. 14;
  10. DoubleE=2. 71;
  11.  
  12. Strbuf<<"Luckynumber"<< Lucky << Endl 
  13. <<"Pi"<< Pi << Endl 
  14. <<"E"<< E << Endl 
  15.  
  16. StringStrval=Strbuf. Str ();/* replace stringstream with a string */
  17. Cout<< Strval;
  18.  
  19. Ofstream outf;
  20. Outf. open ("mydata");/* Create a disk file to read/write */
  21. Outf<< Strval;
  22. Outf. close;
  23.  
  24. Ifstream inf;
  25. Inf. open ("mydata ");
  26. String newstr;
  27. Int lucky2;
  28. Inf>>Newstr>>Lucky2;
  29. If (luky! = Lucky2 ){
  30. Ceer<<"Error wrong lucky number"<< Endl;
  31. }
  32.  
  33. Float pi2;
  34. Inf>>Newstr>>E2;
  35. If (pi2! = Pi ){
  36. Cerr<<"Error wrong pi ."<< Endl;
  37. }
  38.  
  39. Inf. open ("mydata ");
  40.  
  41. While (not inf. eof ()){
  42.  
  43. Getline (inf, newstr );
  44.  
  45. Cout<< Newstr << Endl;
  46.  
  47. }
  48.  
  49. Inf. close ();
  50. Return 0;
  51. }

Stream is the object used for reading and writing. Therefore, it is defined in the standard library, and QT defines to provide corresponding functions. Circulation is often used to read and write files, network connections, and strings. A very useful feature is that it can easily generate strings from Composite data. Iostream defines three global streams:

Cin --- keyboard standard input stream; cout --- console standard output stream console screen); cerr --- standard error stream... A control operator such as flush and endl is also defined. A control operator can be added to the output stream to change the data output format. An input stream is used to change the parsing method of the input data. The reason for using the ostrstream stream is given.

  • Detailed usage and maintenance of the C ++ Library
  • Detailed description of Visual C ++ programming Database
  • Study how to adjust Visual C ++ language by ADO
  • Advanced programmers describe operations on C ++ programs
  • Analysis of Visual C ++'s two complete Windows Applications

Iostream provides input and output support for built-in type objects and file input and output. class designers can expand the C/C ++ library, to support custom types of input and output operations getline and> what is the difference between operators? The getline (istream & in, string & s) function is used to read strings from the input stream in to s and separate them with linefeeds & apos; \ n & apos. What is the difference between pointer and reference?

  • Detailed usage and maintenance of the C ++ Library
  • Detailed description of Visual C ++ programming Database
  • Study how to adjust Visual C ++ language by ADO
  • Advanced programmers describe operations on C ++ programs
  • Analysis of Visual C ++'s two complete Windows Applications

From a symptom perspective: A pointer can change the value it points to at runtime, but the reference will not change once it is bound to an object. From the memory allocation perspective: the program allocates a memory area for the pointer variable, but the reference does not allocate a memory area. A reference must always point to some objects.

In C/C ++, the reference should be initialized. The fact that there is no reference pointing to a null value means that the code to be referenced is more efficient than the pointer. Why does the main (int argc, char argv []) function sometimes contain parameters? What are their functions?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.