file-io

Read file faster by multiple readers

落爺英雄遲暮 提交于 2020-01-04 14:32:13
问题 So i have a large file which has ~2 million lines. The file reading is a bottleneck in my code. Any suggested ways and expert opinion to read the file faster is welcome. Order of reading lines from that text file is unimportant. All lines are pipe '|' separated fixed length records. What i tried? I started parallel StreamReader s and made sure that resource is locked properly but this approach failed as i now had multiple threads fighting to get hold of the single StreamReader and wasting

How to assign a value to an enum based on input from a file in C++?

我只是一个虾纸丫 提交于 2020-01-04 14:24:08
问题 I have a file with values like: START and STOP. I also have the following enum declared: enum Type { START, STOP }; I'm trying to set the enum equal to the first value in the file with something like this: enum Type foo; ifstream ifile; ifile.open("input.txt"); ifile >> foo; I'm getting the error: no match for ‘operator>>’ in ‘ifile >> foo’. How do I go about doing this correctly? 回答1: The quickest thing to do is to read in an int and cast it to your Type enum. 回答2: The stream insertion

How to assign a value to an enum based on input from a file in C++?

岁酱吖の 提交于 2020-01-04 14:22:05
问题 I have a file with values like: START and STOP. I also have the following enum declared: enum Type { START, STOP }; I'm trying to set the enum equal to the first value in the file with something like this: enum Type foo; ifstream ifile; ifile.open("input.txt"); ifile >> foo; I'm getting the error: no match for ‘operator>>’ in ‘ifile >> foo’. How do I go about doing this correctly? 回答1: The quickest thing to do is to read in an int and cast it to your Type enum. 回答2: The stream insertion

Text is being over written when it's supposed to be appended

巧了我就是萌 提交于 2020-01-04 09:55:04
问题 This seems really easy (I've done it a million times and never had a problem), but it's killing me. I want to create some SQL scripts based on content in an Excel spreadsheet. To do this I've created a macro that reads a text file using the code below Dim fso As FileSystemObject Set fso = New FileSystemObject Dim stream As TextStream Set stream = fso.OpenTextFile(filepath, 8, False) This is supposed to open the text file for appending and plug in my new values. Unfortunately, it's always

Binary output in Windows

亡梦爱人 提交于 2020-01-04 09:37:11
问题 I wrote a program that reads a binary file, does some process with its contents and writes the results to a different file. In Linux it works perfectly, but in Windows it does not work; the output files are always 1KB... This is a simplified version of the program: #include <stdio.h> void copyFile(char* source, char* dest); int main (int argc, char* argv[]) { if (argc != 3) printf ("usage: %s <source> <destination>", argv[0]); else { copyFile(argv[1], argv[2]); } } void encryptFile(char*

Binary output in Windows

拥有回忆 提交于 2020-01-04 09:37:09
问题 I wrote a program that reads a binary file, does some process with its contents and writes the results to a different file. In Linux it works perfectly, but in Windows it does not work; the output files are always 1KB... This is a simplified version of the program: #include <stdio.h> void copyFile(char* source, char* dest); int main (int argc, char* argv[]) { if (argc != 3) printf ("usage: %s <source> <destination>", argv[0]); else { copyFile(argv[1], argv[2]); } } void encryptFile(char*

Scanner, nextInt and InputMismatchException

吃可爱长大的小学妹 提交于 2020-01-04 05:27:44
问题 I'm trying to read a text file and then print out the integers in a loop using the nextInt() function in Java. The text file I have is of the form: a 2000 2 b 3000 1 c 4000 5 d 5000 6 Here is my code: public static void main(String[] args) throws FileNotFoundException { String fileSpecified = args[0] + ".txt"; FileReader fr = new FileReader(fileSpecified); BufferedReader br = new BufferedReader (fr); Scanner in = new Scanner (br); while (in.hasNextLine()) { System.out.println ("next int = " +

C++ Ignore Empty First Line

随声附和 提交于 2020-01-04 05:26:09
问题 How do I ignore an empty first line in "input.txt"? I don't necessarily know that there is an empty line (in this particular case there is, but I want to make my code generic), so I need to be able to read the line if there is information, or skip it if it is blank. This is just for the first line. while (getline(mcFile, line)) { istringstream liness2(line); ... } That's how I'm reading the lines. If I knew for certain that any input file I ran this on had an empty first line, I would just do

Jena library is not writing output to an external RDF/XML file

╄→гoц情女王★ 提交于 2020-01-04 05:24:23
问题 I am having an issue with my jena library's writing method. I have following piece of code which is supposed to write the output in external file but it is not doing so. import com.hp.hpl.jena.rdf.model.*; import com.hp.hpl.jena.vocabulary.*; import com.hp.hpl.jena.rdf.model.impl.ModelCom; public class Tutorial04 extends Object { // some definitions static String tutorialURI = "http://hostname/rdf/tutorial/"; static String briansName = "Brian McBride"; static String briansEmail1 = "brian

How to Generate the HTTP Content-Type Header in C?

孤街醉人 提交于 2020-01-04 04:13:10
问题 So I'm working on a networking assignment to produce a basic HTTP/1.0 web server in C. I have most of it figured out, but one of the requirements is that it properly populate the Content-Type field in the header, and I can't seem to find any way to do this automatically. I'm already using fstat() to get the file size and when it was last modified, and I noticed that also includes a "st_objtype" field, but after some research it looks like this is just the AS/400 object type (which is