eof

Python unexpected EOF while parsing

五迷三道 提交于 2019-11-26 03:26:47
问题 Here\'s my python code. Could someone show me what\'s wrong with it. while 1: date=input(\"Example: March 21 | What is the date? \") if date==\"June 21\": sd=\"23.5° North Latitude\" if date==\"March 21\" | date==\"September 21\": sd=\"0° Latitude\" if date==\"December 21\": sd=\"23.5° South Latitude\" if sd: print sd And Here\'s what happens: >>> Example: March 21 | What is the date? Traceback (most recent call last): File \"C:\\Users\\Daniel\\Desktop\\Solar Declination Calculater.py\", line

How does ifstream's eof() work?

烂漫一生 提交于 2019-11-26 02:19:51
问题 #include <iostream> #include <fstream> int main() { std::fstream inf( \"ex.txt\", std::ios::in ); while( !inf.eof() ) { std::cout << inf.get() << \"\\n\"; } inf.close(); inf.clear(); inf.open( \"ex.txt\", std::ios::in ); char c; while( inf >> c ) { std::cout << c << \"\\n\"; } return 0; } I\'m really confused about eof() function. Suppose that my ex.txt\'s content was: abc It always reads an extra character and shows -1 when reading using eof() . But the inf >> c gave the correct output which

eof() bad practice? [duplicate]

筅森魡賤 提交于 2019-11-26 02:02:16
Possible Duplicate: Why is iostream::eof inside a loop condition considered wrong? So I've been using the eof() function in a lot of my programs that require file input, and my professor said that it is fine to use but a few people on SO have said that I shouldn't use it without really specifying the reason. So I was wondering, is there a good reason? You can use eof to test for the exact condition it reports - whether you have attempted to read past end of file . You cannot use it to test whether there's more input to read, or whether reading succeeded, which are more common tests. Wrong:

eof() bad practice? [duplicate]

南笙酒味 提交于 2019-11-26 01:08:33
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why is iostream::eof inside a loop condition considered wrong? So I\'ve been using the eof() function in a lot of my programs that require file input, and my professor said that it is fine to use but a few people on SO have said that I shouldn\'t use it without really specifying the reason. So I was wondering, is there a good reason? 回答1: You can use eof to test for the exact condition it reports - whether you

End of File (EOF) in C

不问归期 提交于 2019-11-26 00:46:21
问题 I am currently reading the book C Programming Language by Ritchie & Kernighan. And I am pretty confused about the usage of EOF in the getchar() function. First, I want to know why the value of EOF is -1 and why the value of getchar()!=EOF is 0. Pardon me for my question but I really don\'t understand. I really tried but I can\'t. Then I tried to run the example on the book that can count the number of characters using the code below but it seems that I never get out of the loop even if I

What is EOF in the C programming language?

别说谁变了你拦得住时间么 提交于 2019-11-26 00:44:05
问题 How do you get to see the last print? In other words what to put in for EOF? I checked the definitions and it says EOF is -1. And if you enter Ctrl-D you won\'t see anything. #include <stdio.h> int main() { int c; while((c = getchar() != EOF)) { printf(\"%d\\n\", c); } printf(\"%d - at EOF\\n\", c); } 回答1: On Linux systems and OS X, the character to input to cause an EOF is Ctrl - D . For Windows, it's Ctrl - Z . Depending on the operating system, this character will only work if it's the