C + + first glimpse of IO

(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:

分类:CPP 时间:2010-04-27 人气:223
blog comments powered by Disqus


  • string中c_str(),data(),copy(p,n)函数的用法总结 2014-09-20

    以下是对string中c_str(),data(),copy(p,n)函数的用法进行了详细的介绍,需要的朋友可以过来参考下 标准库的string类提供了3个成员函数来从一个string得到c类型的字符数组:c_str().data().copy(p,n). 1. c_str():生成一个const char*指针,指向以空字符终止的数组. 注: ①这个数组的数据是临时的,当有一个改变这些数据的成员函数被调用后,其中的数据就会失效.因此要么现用先转换,要么把它的数据复制到用户自己可以管理的内存中.

  • oracle data buffer hit ratio 2010-06-08

    Data buffer hit ratio should be close to 1 select 1-a.PHYSICAL_READS / (a.DB_BLOCK_GETS + a.CONSISTENT_GETS) from v $ buffer_pool_statistics a Or select round ((1 - sum (decode (name, 'physical reads', value, 0)) / (Sum (decode (name, 'db block gets'

  • Unspecified error, an Oracle error occurred, but can not retrieve the error message from Oracle Data type is not supported. 2011-01-21

    Read from the database BLOB type (a variety of methods, ado, odbc, nhibernate), have appeared this error: Unspecified error \ r \ n an Oracle error occurred, but can not retrieve the error message from Oracle. \ R \ n data type is not supported. Conn

  • String or binary data would be truncated The statement has been terminated 2011-07-07

    Possible for the master, this is a non-issue, today I write the steps to solve this problem, I believe that for a rookie like me can be drawn from analysis of the problem. Today, companies need a large amount of data from one table into another table

  • Using java file input stream and file output stream for file read and write use cases! 2010-06-20

    package com.test.io; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; / ** * * @ Author Ad

  • error LNK2001: unresolved external symbol VC + + link error Detailed 2010-10-04

    Learning VC + + link error often encountered when LNK2001, the error is very annoying, because for the programmer, the best compilation error than the error changed, but in general a connection error occurs, the compiler are passed. Have connected th

  • Bash string processing (and Java control) - 14 to determine whether it contains another string (up to 6 ways) 2011-09-27

    Bash string processing (and Java control) - 14 to determine whether it contains another string (up to 6 ways) In Java String.contains & String.indexOf String.contains method can only determine whether it contains a sub-string, can not determine wheth

  • suse11.4 install memcache error array subscript is above array bounds to solve 2011-09-29

    suse11.4 install memcache error: make error "array subscript is above array bounds" This is memcache in suse11.4 on a bug. So need a patch to solve the applying a found patch (https://svn.erp5.org/repos/public/erp5/trunk/patches/memcached-1.4-fi

  • ORACLE: a string of multi-line data makes up 2010-06-03

    The article is written in ibatis, the need to return a string, it returns a multi-line data, resulting in an error. In fact, I want to do is: Query table in a field, return the multi-line, put so many lines of data makes up a string. Cases: id name 1

  • Oracle Database Data buffer size 2010-03-30

    Data block buffer cache (Data block buffers cache): 8i is db_block_buffers * db_block_size, 9i and later to replace the parameters with db_cache_size. 10g, this parameter is automatically managed by the oracle itself, can not manually set. In the mem

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.375 (s). 12 q(s)