Which C master can help solve the getline problem

Updated on number 2024-04-17
14 answers
  1. Anonymous users2024-02-07

    If the screen is flashing.

    Just add a sentence at the end.

    cin>>ch;

  2. Anonymous users2024-02-06

    The program is okay What compiler is used?

  3. Anonymous users2024-02-05

    GetLine is a standard C++ library function; However, it is not a C standard library function, but a standard library function defined by PoSix (IEEE STD version and above) (before the Posix IEEE STD standard came out, it was only a function in the GNU extension library).

    GetLine function synopsis:

    The member function getline() reads a line of characters from the input stream, and when it reads the terminator, it will be added'0'Stored in the result buffer as a termination of the input. The terminator can be either the default terminator or the defined terminator. The syntactic structure of a function is:

    getline ("Character Array CHS>, "Number of Characters to Read N>, "Terminator").

    The function ends when the function encounters a character equal to the end delimiter, and the function draws out the delimiter, in which case the delimiter is neither put back into the input stream nor into the string to be generated. Therefore, it can be understood that the first carriage return after the input is a delimiter, which is discarded after being confirmed, and the second one is what is normally needed when the program is executed.

  4. Anonymous users2024-02-04

    istream& getline ( istream& ,string& )

    They all read the characters of the input stream into the string, the top one ends with the terminator you set, and the bottom one ends with a line break''As an end. If you read an EOF or encounter an error, it will also end.

  5. Anonymous users2024-02-03

    GetLine is an input function in C++ that reads entire rows of data from standard input and saves them as an array of characters (char* or cha).

    There are two types of overloads for getline:

    1、 istream& getline(char* s, int n);

    This is done by reading the entire line of data from the input and ending the input when a line break is encountered. If, during the input process, the actual number of characters entered exceeds the value of the parameter n, the input will also be terminated. The input result is stored in the space pointed to by the character pointer S.

    2、istream& getline(char* s, int n, char delim);

    This overload has one more character delim than in 1, and its function is to set the ending character.

    When reading in, the input ends when the character is equal to the delim value. Except for that, the others are the same as in 1.

    i.e., getline(s,n);

    Equivalent to getline(s,n,'');

  6. Anonymous users2024-02-02

    Get the data of the open file in a row.

  7. Anonymous users2024-02-01

    There are essentially two GetLine functions in C++, one in the header file, which is a member function of the iStream class. One in the header file, which is a normal function.

    1. There are two overloaded forms of the getline function in

    istream& getline (char* s, streamsize n );

    istream& getline (char* s, streamsize n, char delim );

    The function is to read up to n characters from istream and save them in the array corresponding to s. Even if you haven't read enough n characters, if you encounter a line break''(first form) or delim (second form), then the read terminates''or delim will not be stored in the array corresponding to s.

    2. There are four overloaded forms of the getline function in

    istream& getline (istream& is, string& str, char delim);istream& getline (istream&& is,string& str, char delim);istream& getline (istream& is, string& str);

    istream& getline (istream&& is, string& str);

    The usage is similar to the previous one, but the istream to be read is passed in as a parameter is. The read string is stored in a str of type string.

  8. Anonymous users2024-01-31

    char s[1000];A number in parentheses less than 1000 may be wrong, but not necessarily wrong, for reasons mentioned above).

    or char* s=new char[1000];

    or char a[1000]; char * s=a;

    or char a[1000]; char *s=&a[0];

  9. Anonymous users2024-01-30

    getline

    Syntax: The getline() function is used to input the stream, reading characters into the buffer until the following happens:

    num - 1 character has been read in, touched by a line break flag, touched by an eof, or, arbitrarily read in until the read character character character will not be put into the buffer.

  10. Anonymous users2024-01-29

    GetLine function getline is a member function of a String class object, which belongs to the String IO operation. Used to read entire lines of text.

    getline parameter getline(cin,str); cin: input stream str: string object.

    GetLine indicates that the getline function reads from the next line of the input stream and saves the read content to str, but does not include line breaks. The getline function takes the istream parameter as the return value, and uses it as a judgment condition just like the input operator. Example:

    #include #include using namespace std;int main() result: Enter line1 -- enter the line return and show empty enter line2 --enter the line entry line 1 enter line3 --enter the line 2 -- and so on.

  11. Anonymous users2024-01-28

    <>1. The member function getline() reads a line of characters from the input stream, and when it reads the terminator, it will store 0 in the coincidental result buffer as the termination of the input. The terminator can be either the default terminator or the defined terminator. The syntactic structure of a function is:

    getline(character array chs>, the number of characters read n>,)

    2. When the function encounters a noisy character equal to the end delimiter, the function ends and the function extracts the delimiter, in which case the delimiter is neither put back into the input stream nor into the string to be generated. Therefore, it can be understood that the first Zheng key carriage return after the input is a delimiter, which is discarded after being confirmed, and the second one is what is normally needed when the program is executed.

  12. Anonymous users2024-01-27

    #if defined(_gnu_source) |posix_c_source >= 200809l

    #include

    function declaration: ssize t getline(char **lineptr, size t *n, file *stream);

    Return Value: Success: Returns the number of bytes read.

    Failed: Returns -1.

    Parameter: lineptr: a pointer to store the characters in the line, if it is null, there is a system to help malloc, please release it freely after using it.

    n: If it is the pointer of the system malloc, please fill in 0

    stream: file descriptor.

  13. Anonymous users2024-01-26

    In C++, the GetLine function is used to read an entire row of data from the standard input stream Cin. That is, by default, getline does not read which file it reads, but the keyboard input in the command line.

    To read a file using getline, the first thing to do is to redirect CIN to the file you want to read. This can be achieved with the following **.

    streambuf *backup;

    ifstream fin;

    );Open the file you want to read.

    backup = ;Back up the buffer of the CIN itself.

    Redirect the buffer of the cin to the file.

    Perform the required read operations, including getline.

    Restore the original CIN buffer.

    After execution, you can use getline to read the entire line of data from the file.

    GetLine can be called in the following way:

    getline(char

    buf,int

    size);

    If the data length exceeds the length specified by size, only the size byte data is read.

  14. Anonymous users2024-01-25

    There are two ways to input a line of string to an input stream through a standard input device: the get function and the getline function, both of which are member functions of the istream-like object cin, and let's take a look at the differences between the two.

    getline function.

    The getline() function reads the entire line, and it uses the newline entered by the Enter key to determine the end of the input, but does not save the newline, instead, when storing the string, he replaces the newline with a null character. To call the function, you can use strnum), the first parameter represents the name of the array used to store the input row, and the second parameter represents the number of characters entered. If the number of characters is 20, the function can read up to 19 characters, and the rest is used to store the null characters that are automatically added at the end.

    The getline function stops reading when it reads a specified number of characters or encounters a line break.

    get function.

    There are several variations of the get function, one of which is very similar to getline, it receives the same parameters, interprets them in the same way, and both reads to the end of the line, but get doesn't read and discard the line break, but leaves it in the input queue.

    Let's say get(:) is called twice

    size1);

    size2);

    Since the newline character will remain in the input queue after the first call, the first character seen on the second call is the newline, so the second get function thinks that the end of the line has been reached without finding anything readable, i.e. the array name2 value is empty.

    The workaround is with the help of get(), a function without parameters. Its function is to read the next character.

    size1);,size2);

    Note: The size) function still returns a cin object, so the above ** can be written as.

    size1).get();

Related questions
12 answers2024-04-17

It's not good, it's not as good as the mainstream products. It's a matter of time before it's time to be eliminated. If the memory is a little larger, and the graphics card is stronger, it's basically fine.

3 answers2024-04-17

As long as you say, as long as you don't start, it's good to smell the word [university], but you feel that the shop is all the works in storage, but right], on the other hand, you raise the individual and line every day you put the facts moving. Its scope can be called the workplace with all means"Question"It seems to be. "Question", ask for a sip, but various. >>>More

6 answers2024-04-17

The system is testing IDE equipment, and now there are many IDE interfaces on the motherboard, generally more than 4. >>>More

2 answers2024-04-17

first of all, i am sorry about the disapperment before. my msn's password has been changed by my brother. the reason is hope me to thinking about the problem between you and me. >>>More

15 answers2024-04-17

Solution: If there are a total of x pencils, then A 1 7x, B 1 4x, C 2 * (1 4x-1 7x). >>>More