| |

VerySource

 Forgot password?
 Register
Search
View: 767|Reply: 4

Simple question about standard input / output

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-16 16:40:01
| Show all posts |Read mode
Will ((ch = getchar ())! = EOF) {
      printf ("% c", ch);
    }
What character is EOF? Why can't you stop.
And what is the value of the newline key (or how to represent the newline key)?
Reply

Use magic Report

0

Threads

5

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 United States

Post time: 2020-1-21 10:36:02
| Show all posts
That should be the eof judgment when reading the file
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-21 20:36:01
| Show all posts
Change (ch = getchar ())! = EOF to
(ch = getchar ())! = '\n'

EOF is used to read files, such as text.txt
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main () {
    ifstream file;
    string line;
    file.open ("text.txt");
    int row = 1;
    while (! file.eof ()) {
        getline (file, line);
        cout << row << "" << line;
        row ++;
        cout << endl;
    }
    file.close ();
    system ("pause");
}
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-22 15:00:01
| Show all posts
while ((ch = getchar ())! = ‘\n’) //\n means a newline
{
      printf ("% c", ch);
}
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-22 16:09:01
| Show all posts
The landlord tried it with Ctrl + z and stopped.
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