Basic functions and syntax of C + + input and output stream

Source: Internet
Author: User

1,expect_* series and Assert_* series.

These two series of functions are used for assertions, that is, to determine whether the requirements are met, the full will output log.

For example, Expect_eq (3,Add (1, 3)) is here to determine if 3 and Add (1, 3) are equal and then output in the result

G:\myproject\c++\gtestdemo\gtestdemo\gtestdemo.cpp (16):

Error:value Of:add (1, 3) Actual:4 Expected:3


This will return the error, because the front is 3 so to equal words to be equal to 3, so the expectation is 3, but 1+3 actual

Returned 4, so error.


Other types are expect_true and expect_false and so on.

Next I say the difference between the two,Expect_ used to play the message, if the error will be executed down, it is said to

View.

The Assert_ is used for checking and exiting the current function (not exiting the current program) once the check fails.

Note: Only the failure of the error will be typed information, success is not hit.


Hardening: If you encounter special circumstances, such as the error in the loop, it is not known that i =? Out of the time, so

Added new elements, <<.

Example, Expect_true (FALSE) << "Mimida?" <<i;

The output is

G:\myproject\c++\gtestdemo\gtestdemo\gtestdemo.cpp (16):

Error:value Of:false Actual:false,expected:true

Mimida? 8 (I=8)//This line is the input and output stream.


2,ifstream

Enter the stream and read the contents of the file into the stream.

For example

std::ifstreaminput("./case/encoding/utf8");

This is where I read the UTF8 into input.


3,getline

Read the variable from the stream element. If it's getline,




Basic functions and syntax of C + + input and output stream

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.