Summary of the getline function in C/C ++
The getline function is a common function. Based on its name, we can know that this function is used to read a row of data. Now we will summarize the getline function.In the standard C language, the getline
Reprinted please indicate the source:Http://hi.baidu.com/leejun_2005/blog/item/702d4888928b15a60e2444b4.htmlRef: http://bbs.chinaunix.net/thread-108596-1-1.html1. Getline usage:Getline is a function used in the awk for input redirection. It can read
Scanf, gets, getchar, cin, cin. get, cin. getline, getline summary, cin. getcin. getline
I. scanf
Scanf can be used to read numbers, characters, and strings;
Conclusion:(1) When scanf reads a single character (% c) from the buffer, if the first
A useful string IO operation: getline. This function takes two parameters: an input stream object and a string object. The Getline function reads from the next line of the input stream and saves the read content to string, but does not include line
Usage of functions such as Cin, Cin. Get (), Cin. Getline (), Getline (), and gets ()
When I was learning C ++, these input functions were a bit confusing. Here I will make a summary. I hope it will be helpful for later users to review them, if
When I was learning C ++, these input functions were a bit confusing. Here I will make a summary. I hope it will be helpful for later users to review them, if there are any errors, please kindly advise (all in this articleProgramAll run through VC 6.
1,CIN
Usage 1: the most basic and common usage. Enter a number:
# Include
Using namespace STD;
Main ()
{
Int A, B;
Cin> A> B;
Cout
}
Input: 2 [Press enter] 3 [Press enter]
Output: 5
Usage 2: accept a string. When "space", "tab", and "Press ENTER"
When I was learning C ++, these input functions were a bit confusing. Here I will make a summary. I hope it will be helpful for later users to review them, if there are any errors, please give me more advice (all the programs in this article are run
I searched the internet for the getline () function for a long time, mostly for C ++. There are many heavy-duty functions in the cloud, and there are no instances. Actually, there is no getline () required by myself () function. Therefore, I ran man
A Getline, on the whole, should understand its usage as such:when the left and right no redirect | or is interlaced. When there is a redirect | or The following code shows both of these usages:awk 'begin{nfile=4Getline for(i=2; i) {
When using C + + 's getline function, two problems are encountered, summarized as follows:1. Sometimes we will find Getline (CIN,STR) When we write the program, such statements are not executed, but are skipped directly,The general solution is to
-----------------------
1. Cin. Get ()
(1). Cin. Get () extract a single character. You can extract carriage return and space.
A = cin. Get ();
(2) Same as (1)
Cin. Get ();
(3 ).
Cin. Get (character array, number of characters N, Terminator
Usage of c++:cin, Cin.getline (), Getline ()Main content:1. CIN Usage2, Cin.getline () usage3, getline () usage3. Issues of attentionFirst, cin>>Usage 1: Enter a number or character#include using namespace Std;Main (){int A, B;cin>>a>>b;cout}Usage 2:
Array:
Float loans [20];
The loans type is not "array" but "float array ". This emphasizes that the loans array is created using the float type.
String:
Char dog [5] = {'A', 'B', 'C', 'D', 'E'}; // not a string (not a string)
Char dog [5] = {'A', '
I searched the internet for half a day getline () function, mostly for C + +, overloaded functions more, foggy, and there is no instance, anyway is not the need for their own getline () function. So, I got a man under Linux and tested it. The
C ++ learners may encounter a Getline () function. For example, in C ++ premer, the second section of the standard string type is "reading the entire line of text with Getline ". The program in the book is as follows: int main () {string line: While
The Getline () function generates a string that contains a string of characters read from the input stream until the generation ends in the following cases.
1) to the end of the file,
2) encounter the delimiters of the function,
3) maximize
Code:1#include 2#include 3 4 using namespacestd;5 6 intMain () {7 8 Char*s;9s =New Char[ -];//space must be allocatedTenCin.getline (s),5); One inti =0; A while(S[i]! =' /'){ -coutS[i]; -i++; the } -coutEndl; -Cin.clear ();//Clear
A few C ++ input functions are always unclear. Let's sum up!
1. Cin
1. Cin. Get ()
2. Cin. Getline ()
3. Getline ()
4. Gets ()
5. getchar ()
1. Cin>
Usage 1: the most basic and common usage. Enter a number:
# Include
Using
I searched the internet for the getline () function for a long time, mostly for C ++. There are many heavy-duty functions in the cloud, and there are no instances. Actually, there is no getline () required by myself () function. Therefore, I ran man
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.