1: The problem exists when using the standard input function, CIN, and the format input function scanf: When a space is entered, the program does not accept the content after the whitespace.
Both the input function gets_s and the output function puts only end with the Terminator ' \ n ' as the input/output end flag.
The code is as follows:
//6.8.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include<iostream>using namespacestd; #include<string>voidMain () {Charstr1[ -],str2[ -],str3[ -],temp[ -]; cout<<"Please enter Hello world!! using scanf and CIN"<<Endl; scanf ("%s", str1);//Enter a space when entered, indicating the end, and then entered the Hellocin>>str2;//default to Wordcout<<"str1:"; printf ("%s\n", STR1); cout<<"str2:"; cout<<str2<<Endl; cout<<"The whitespace left by CIN remains in the input stream, which is used by the get to receive it:"<<Endl; gets_s (temp);//You can enter Hello Word directlycout<<"Temp:"<<temp<<Endl; cout<<"Please enter Hello world!! with gets:"<<Endl; gets_s (STR3); cout<<"STR3:"; Puts (STR3);}View Code
Operation Result:
Introduction to C + + Classic-Example 6.8-gets_s and puts application