eof

fstream EOF unexpectedly throwing exception

。_饼干妹妹 提交于 2019-12-13 16:22:09
问题 My question is very similar to a previous one. I want to open and read a file. I want exceptions thrown if the file can't be opened, but I don't want exceptions thrown on EOF. fstreams seem to give you independent control over whether exceptions are thrown on EOF, on failures, and on other bad things, but it appears that EOF tends to also get mapped to the bad and/or fail exceptions. Here's a stripped-down example of what I was trying to do. The function f() is supposed to return true if a

How do I check that stream extraction has consumed all input?

久未见 提交于 2019-12-13 13:06:49
问题 In the following function, I try to see if a string s is convertible to type T by seeing if I can read a type T , and if the input is completely consumed afterwards. I want template <class T> bool can_be_converted_to(const std::string& s, T& t) { std::istringstream i(s); i>>std::boolalpha; i>>t; if (i and i.eof()) return true; else return false; } However, can_be_converted_to<bool>("true") evaluates to false, because i.eof() is false at the end of the function. This is correct, even though

foreman says “unexpected EOF” in one of the SAME node app in 2 different places

时光毁灭记忆、已成空白 提交于 2019-12-13 09:35:45
问题 i have a sample node.js app in directoryA . Then i did foreman start in that directory and it worked fine. afterwords i copied that app into a new location and tried doing foreman start from there, it didn't work... here is what i did: $ ########## foreman works fine in directoryA ########## $ pwd you/cant/see/me/directoryA $ foreman start 22:28:30 web.1 | started with pid 80332 22:28:30 web.1 | Listening on 5000 ^C $ ########## copy the same node app from directoryA to directoryB ##########

Collect data in chunks from stdin: Python

十年热恋 提交于 2019-12-13 09:07:20
问题 I have the following Python code where I collect data from standard input into a list and run syntaxnet on it. The data is in the form of json objects from which I will extract the text field and feed it to syntaxnet. data = [] for line in sys.stdin: data.append(line) run_syntaxnet(data) ##This is a function## I am doing this because I do not want Syntaxnet to run for every single tweet since it will take a very long time and hence decrease performance. Also, when I run this code on very

How to solve an EOF error when trying to open and read a binary file [duplicate]

南笙酒味 提交于 2019-12-13 08:58:53
问题 This question already has answers here : How to solve an EOF error when reading a binary file (2 answers) Closed 12 months ago . I am learning to write and read from a binary file and am copying code out of a book to illustrates how this is done. I have put together two pieces of code from the book to complete this task. On compilation of my code I get an EOF error and am not sure what is causing it. Can you help? The code I am writing is listed below. class CarRecord: # declaring a class

Special character in the file exit the while loop in Perl

☆樱花仙子☆ 提交于 2019-12-13 08:29:52
问题 I wrote a simple parser for a .txt file with the following instructions: my $file2 = "test.txt"; open ($process, "<",$file2) or die "couldn't manage to open the file:$file2!"; while (<$process>) { ... } In some files that I am trying to parse there is a special character that is like the right arrow (->) and that I don't manage to paste here from the file. Every time the parser hits that character (->), it exits the file without processing it till the end. Is there a way to avoid it and

Question about while(!EOF)

三世轮回 提交于 2019-12-13 01:14:36
问题 Im reading in values from stdin and I want to keep reading the file until I have completed reading it all the way, so I am using while(!EOF){ scanf(...) } However, the code fragment doesn't seem to do anything, while(!EOF){ scanf("%d %d %d %d", &imageWidth, &imageHeight, &safeRegionStart, &safeRegionWidth); printf("---imageWidth=%d imageHeight=%d safeRegionStart=%d safeRegionWidth=%d---\n", imageWidth, imageHeight, safeRegionStart, safeRegionWidth); totalP = imageWidth * imageHeight ;

why use EOF to check if stdin buffer is cleared

感情迁移 提交于 2019-12-12 22:18:17
问题 Say I have the following... int main () { char name [5] = ""; char c; printf("Enter a name: "); fgets(name,5,stdin); while ((c = getchar()) != '\n'); printf("Exiting...); getchar(); return 0; } The while loop will clean the stdin buffer but I have seen the loop done like this as well... while ((c = getchar()) != '\n' && c != EOF); I am wondering if there is any difference between the 2??? Does testing for EOF make any difference? 回答1: I am wondering if there is any difference between the 2???

Disabling EOF (0x1A) using SerialPort [closed]

独自空忆成欢 提交于 2019-12-12 13:09:58
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I know there are other posts which have addressed this fact but I have still been unable to find a solution to my problem. I am received massive chunks

Does EOF actually exist?

て烟熏妆下的殇ゞ 提交于 2019-12-12 13:07:10
问题 When I use file functions in PHP, I check for EOF. I wonder if EOF actually exist in a file. When I create an empty text file, it displays 0KB. How does EOF exist in a file with 0KB? 回答1: There is an end-of-file control character (in the ASCII character set it's CTRL+Z or 26 or 0x1A), but it hasn't actually been needed to mark the end of a file since OSes released in the 80's. All modern OSes store the file size as metadata in the directory structure (exact format depends on filesystem) and