eof

eof() function not working c++ stuck with infinite loop [duplicate]

北城余情 提交于 2020-01-05 06:40:02
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why is iostream::eof inside a loop condition considered wrong? im having a problem with the eof() function. my loop is not reading the end of the file that im reading from thus leaving me with an infinite loop. Any help or insight would be greatly appreciated. thanks while (!file2.eof()) { getline (file2, title, ','); getline (file2, authorf, ','); getline (file2, authorl, ','); getline (file2, isbn, ','); file2

eof() function not working c++ stuck with infinite loop [duplicate]

a 夏天 提交于 2020-01-05 06:39:20
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why is iostream::eof inside a loop condition considered wrong? im having a problem with the eof() function. my loop is not reading the end of the file that im reading from thus leaving me with an infinite loop. Any help or insight would be greatly appreciated. thanks while (!file2.eof()) { getline (file2, title, ','); getline (file2, authorf, ','); getline (file2, authorl, ','); getline (file2, isbn, ','); file2

Recover stdin from eof in C

牧云@^-^@ 提交于 2020-01-03 17:26:34
问题 I am using the C code below to read user input from a terminal. If the user inputs EOF, e.g. by pressing ^C, stdin is closed and subsequent attempts to read from it, e.g. via getchar() or scanf(), will cause an exception. Is there anything I can do in C to "recover" my program, in the sense that if some user accidently inputs EOF, this will be ignored, so I can read from stdin again? #include <stdio.h> int main(void) { int res_getchar=getchar(); getchar(); return 0; } 回答1: Using ungetc() to

How i can read tty file with timeout?

牧云@^-^@ 提交于 2020-01-03 13:08:37
问题 I have tty device in /dev , where I send AT commands. I want to read line by line and stop reading file after timeout. 回答1: You can use the program stty to configure the tty device. To see the settings for terminal /dev/ttyS0, try stty -a -F /dev/ttyS0 The default settings regarding timeout are min = 1; time = 0 , which means that the reading program will read until at least one character has been read and there is no timeout. Using e.g. stty -F /dev/ttyS0 min 0 time 10 the reading program (e

boost::asio::async_read() of stream_descriptor now returning EOF

主宰稳场 提交于 2020-01-03 05:12:32
问题 Upgraded Ubuntu today from 14.10 to 15.04. Now seeing different behaviour either in boost::asio::async_read() , boost::asio::posix::stream_descriptor , or tap/tun interfaces. Calling async_read() immediately returns boost::asio::error::eof . If I ignore the error and loop back up to start a new async_read() it does eventually read when bytes are available, and the application continues to work. The problem with doing this workaround loop is the application now consumes 100% of a core as it

Behavior of using \Z vs \z as Scanner delimiter

孤者浪人 提交于 2020-01-02 04:30:09
问题 [Edit] I found the answer, but I can't answer the question due to restrictions on new users. Either way, this is a known bug in Java. http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8028387 I'm trying to read a file into a string in Java 6 on 64 bit ubuntu. Java is giving me the very strange result that with "\\Z" it reads the entire file, but with "\\z" it reads the entire string up to 1024 characters. I've read the Java 6 API for all the classes and I am at a loss. Description of \Z and

BufferedReader reset fail after read to end of file

非 Y 不嫁゛ 提交于 2019-12-31 03:01:43
问题 I have a BufferedReader wrapped on a file, I want to mark a place and use reset() later to get back to this position. I have read the java api, it states mark (readlimit), when read too many bytes, the reset will fail. So i figure I can set a large limit. However if i have code BufferedReader br=...; br.mark(1024000); // large but not as large as file. while(br.ready()){ //keep reading. to find some stuff. } //now the br.ready() is false br.reset() // It will fail with mark invalid exception

Huffman encoding - header & EOF

孤街浪徒 提交于 2019-12-30 11:28:25
问题 I am currently working on implementing a program based on the huffman algorithm in Java, and I am at the stage where I need to output the encoded content to a file. I am a bit confused about how to implement the header and eof needed for decoding. For my header at the moment I have all the unique values that occur from the input file and their frequency, but on some articles I have seen people do it with 0 or 1 represents the nodes and then the frequency (which I am a bit puzzled by as it

Token error: EOF in multi-line statement

旧巷老猫 提交于 2019-12-30 04:20:07
问题 The following code gives me this error "Token Error: EOF in multi-line statement". What is this error? How can I fix it? import easygui import time namegui = easygui.enterbox(msg='Enter your name:', title='Name query', default='Gian') situationgui = easygui.enterbox(msg='Please enter your situation:', title='Thought Log(Situation)') thoughtsgui = easygui.enterbox(msg='Please enter your thoughts:', title='Thought Log(Thoughts') emotionsgui = easygui.enterbox(msg='Please enter your emotions: \n

How to read from std::cin until the end of the stream?

大城市里の小女人 提交于 2019-12-29 09:05:54
问题 My problem is, that I want to read the input from std::cin but don't know how long the input is. Also I have to char and can't use std::string . There are two ways I have to handle: a) The user inputs text and when he hits [ENTER] the program stops reading. b) The user redirects std::cin to a file (like .\a.oput < file ) which can hold multiple lines. Edit: Just noticed that std::cin.eof() is always false also in the case of reading form a file. For a) I could read until \n occures. For b)