The pit is dead .. I was bothered by this problem for more than half a semester , Today, I searched around and finally found out some , It's better to use these methods in the future, otherwise there will always be mistakes QAQ
The actual test examples are not included , Dead memory is enough here T-T

Concept :

gets() function : From standard input devices ( keyboard ) Read the string until the end of the newline .

cin Can continuously read the desired data from the keyboard , With spaces 、tab Or wrap as a separator .

scanf("%s",str) You can continuously read the desired string from the keyboard ( Array ), With spaces 、tab Or wrap as a separator .

Basic usage :

C Language : Read in a string with spaces and use gets()         The header file #include<stdio.h>

Read in a string without spaces and use scanf("%s",str)      The header file #include<string.h>

C++:      Read in a string with spaces and use gets()        The header file #include<iostream>

Read in a string without spaces and use cin        The header file #include<cstring>

I have a small problem :

In general use ACM These input functions are used many times ,
But if that happens : The length of the first input string is greater than that of the second input string .
that strlen What happens when you measure the length of a string ?
After testing, the conclusion is The measured length is the length of the second string ( It turns out that the first time I read in many strings is still )

ACM More articles on string input

  1. 【 Make up for it , Because maybe the topic will come out for the third time !!】ACM character string - Combinatorial mathematics ( The official answer is digital DP To write )

    ACM character string . The length cannot exceed n . The string contains only uppercase letters . The generated string must contain the string “ACM”,ACM Strings need to be connected together ! ok, Is it simple ? Now let me tell you n Value , You can tell me how many strings there are Input ...

  2. fscanf( Format string input )

    fscanf( Format string input ) Correlation function scanf,sscanf Header file #include<stdio.h> Defined function int fscanf(FILE * stream ,const ...

  3. C String input and output functions

    Let's make a small summary of several commonly used string input and output functions TAT Add header file when using :#include<stdio.h>. scanf(" Format control string ", Variable address list ):(pri ...

  4. cin String input

    cin String input I'm learning c When , About string input , Remember to have  scanf("%s",s); gets(s); also ...o.o I don't think so ... scanf("%s&quo ...

  5. C++ One line of string input at a time ( Learning notes ) ( turn )

    1. Line oriented input :getline()getline() Function reads the entire line , It uses the newline character entered by the Enter key to determine the end of the input . cin.getline(Arr, 20) // Arr Is the name of the array used to enter rows :   ...

  6. C Language &#183; String input and output functions

    Algorithm improvement 3-2 String input and output functions   The time limit :1.0s   Memory limit :512.0MB      describe Write function GetReal and GetString, stay main Function to call these two functions respectively . Reading in a real number ...

  7. C/C++ String input with spaces

    One . String input with spaces ( One )C++ piece 1. For character arrays Method 1 getline() Read in the whole line of data , Use enter to enter a newline character to determine the end of the input . Calling method : cin.getline(str,len) ...

  8. Number of words HDU 2072 String input control

    Number of words HDU 2072 String input control The question lily Good friends xiaoou333 It's very empty recently , He thought of a meaningless thing , It is to count the total number of different words in an article . Your next task is to help xiaoou333 Solve this ...

  9. Java Realization Blue Bridge Cup VIP Algorithm improvement 3-2 String input and output functions

    Algorithm improvement 3-2 String input and output functions The time limit :1.0s Memory limit :512.0MB describe Write function GetReal and GetString, stay main Function to call these two functions respectively . After reading in a real number and a string , take ...

Random recommendation

  1. Mysql Use of query statement select.. for update Analysis of database deadlock caused by

    There is a business need in the near future , Multiple machines need to run from Mysql Query data in a table and do subsequent business logic , To prevent multiple machines from getting the same data at the same time , Each machine needs to lock the data segment to get the data , Make sure that multiple machines don't get the same data . We My ...

  2. NDK note ( Two )- stay Android Studio Use in ndk-build

    We are in touch with the previous article CMake, This one is about ndk-build Process of use . Just used , Write where you want to . Environmental background Android Development IDE edition :AndroidStudio 2.2 Above version ( It has been upgraded to ...

  3. input You can only enter numbers and limit the length

    <style> /* stay chrome Remove under input[number] The up and down arrows of */ input::-webkit-outer-spin-button,input::-webkit-inner ...

  4. #pragma data_seg Shared data area ( turn )

    Original address :http://www.cnblogs.com/CBDoctor/archive/2013/01/26/2878201.html 1)#pragma data_seg() Commonly used in DLL in . It's just ...

  5. 【Andorid------ Gesture recognition 】GestureDetector and SimpleOnGestureListener The use of the tutorial ( turn )——

    FROM:http://www.cnblogs.com/transmuse/archive/2010/12/02/1894833.html 1. When the user touches the screen , There will be a lot of gestures , for example down,u ...

  6. HDU3952- The geometric

    The question : to n Fruit , Each fruit includes m A little bit ( namely m side ), Judge the number of fruits that can be cut by one knife : Ideas : The data is small ,n <= 10,m <= 10; You can enumerate , Enumerate any two points of two fruits , In a straight line , however ...

  7. npm + webpack +react

    Embark on a journey Before we start , You need to put your Node.js and NPM All updated to the latest version . visit  nodejs.org  Check out the installation details . We will use NPM Install some tools . Start using Webpack It's simple , ...

  8. destoon How to add new menu to store management homepage

    1. open /lang/zh-cn/home.inc.php, find 9,10 Replace the line with : $HMENU = $DMENU = array(' Company introduction ', ' Supply products ', ' Purchase list ', ' Information Center ', ' Rong ...

  9. understand Lambda expression

    1. What is? Lambda expression Lambda Expression is an anonymous method , Usually in LINQ Is used to create a delegate Simply speaking . It's a no statement , No access modifier , no return value . There's not even a way to name . 2. Why do we need to use La ...

  10. Java IO Summary of learning notes

    Java IO Summary of learning notes Preface The previous eight articles have described in detail Java IO Operation method , The list of articles is as follows Basic file operations Operation of character stream and byte stream InputStreamReader and OutputStreamW ...