| |

VerySource

 Forgot password?
 Register
Search
View: 854|Reply: 2

Several functions that need to be clarified urgently, urgently~~~~!!!

[Copy link]

3

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-9 16:00:02
| Show all posts |Read mode
The specific usage of in, cin, sin, getline() and what operator is encountered to stop input
If there is a file to enter:
aaa.txt:
5
1 2 4 5 2 3 7 8
9 8 9
4 0 9 8 2
What is the difference between input using these 4 methods, and what is the result?
What does ignore() mean, and how to use it? Hope you all give me some pointers, thank you!
Reply

Use magic Report

0

Threads

49

Posts

34.00

Credits

Newbie

Rank: 1

Credits
34.00

 China

Post time: 2021-3-9 16:15:01
| Show all posts
in,sin//No such thing, it should be in or sin in istream in("a.txt");
Cin//The global object of istream stored in iostream, usage:
int i;
cin>>i;
string t;
cin>>t;

getline usage
    std::string s;
    while (getline(std::cin,s)) {//End with '\n'
        ...
    }
    while (getline(std:: cin, s,':')) {//End with':'
        ...
    }

In addition, istream also has a getline member function, usage:
getline(s, num) can read at most num -1 characters, ending with '\n', including '\n'
getline(s, num, t) ends with t, others are the same as above

ignore():
istream&istream::ignore ()//Skip a character

istream&istream::ignore (streamsize count)//Skip count characters

istream&istream::ignore (streamsize count, int delim)//Skip count characters or encounter delim
Reply

Use magic Report

3

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 United States

 Author| Post time: 2021-3-9 17:00:01
| Show all posts
The default of ignore() is to skip carriage returns or space characters?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list