C + + first glimpse of IO

sponsored links
(1) Do you really understand the "cout <<endl;" significance?

Many people know that endl is a special value, called a manipulator (manipulator). Its role is to wrap the output results. But just more than that, it should refresh the buffer associated with the device (buffer). When we cout <<"a string show" when the string is written to the output device of the buffer, the user can not see the screen in time string. But to wait until the data buffer is flushed before they are reflected to the external device. The output of endl will flush the buffer in time.

This is a very important thing. We programmers often insert the output statements in the code for debugging. Since this time will be great use of endl. Consider the following code:


int main(){
    int p[100];
    cout<<"there is error below!";  // Standard output  
    p[101]=1;  // Error location, the array is out of range  
    return 0; 

Obviously, the run to the line 6 has a runtime error (array bounds checking by the compiler will not come). But the supposedly should print out "there is error below" error after the. So that we can quickly navigate to the following error appears in the standard output. However, the results of running nothing but the output? We changed a bit code to the output line 5 changed: cout <<"there is error below!" <<Endl; can see the strings on the screen, and it will be too small, it appears the system run error.

Sum up: we insert the output of debugging statements, should be promptly flushed the output stream. Forgotten endl may result in the output string to stay in the buffer, if the program crashes, it will lead to erroneous inference ending crash.

(2) the characteristics of standard input?


int main(){
     int v1,v2;
     cin>>v1>>v2;  // Enter two integer  
     return 0;

We can screen through this in several ways to enter two integer variables v1 and v2:
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of C + + first glimpse of IO

  • Hibernate configuration parameters hibernate.hbm2ddl.auto

    Hibernate in the configuration file: <properties> <property name="hibernate.hbm2ddl.auto" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @

  • In the servlet use Bean

    According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • can not be represented as java.sql.Timestamp

    Development of procedures for the use of hibernate when, some time there is no need to fill in the fields, but after the hibernate query time reported "Java.sql.SQLException: Value'0000-00-00 'can not be represented as java.sql.Timestamp ...

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries