file-io

Read a binary file (jpg) to a string using c++

孤人 提交于 2019-12-30 04:20:07
问题 I need to read a jpg file to a string. I want to upload this file to our server, I just find out that the API requires a string as the data of this pic. I followed the suggestions in a former question I've asked Upload pics to a server using c++ . int main() { ifstream fin("cloud.jpg"); ofstream fout("test.jpg");//for testing purpose, to see if the string is a right copy ostringstream ostrm; unsigned char tmp; int count = 0; while ( fin >> tmp ) { ++count;//for testing purpose ostrm << tmp; }

Read a line of input faster than fgets?

梦想与她 提交于 2019-12-30 03:08:27
问题 I'm writing a program where performance is quite important, but not critical. Currently I am reading in text from a FILE* line by line and I use fgets to obtain each line. After using some performance tools, I've found that 20% to 30% of the time my application is running, it is inside fgets . Are there faster ways to get a line of text? My application is single-threaded with no intentions to use multiple threads. Input could be from stdin or from a file. Thanks in advance. 回答1: You don't say

How can I speed up line by line reading of an ASCII file? (C++)

点点圈 提交于 2019-12-30 02:09:12
问题 Here's a bit of code that is a considerable bottleneck after doing some measuring: //----------------------------------------------------------------------------- // Construct dictionary hash set from dictionary file //----------------------------------------------------------------------------- void constructDictionary(unordered_set<string> &dict) { ifstream wordListFile; wordListFile.open("dictionary.txt"); std::string word; while( wordListFile >> word ) { if( !word.empty() ) { dict.insert

Remove beginning of file without rewriting the whole file

◇◆丶佛笑我妖孽 提交于 2019-12-30 01:47:42
问题 I have an embedded Linux system, that stores data in a very large file, appending new data to the end. As the file size grows near filling available storage space, I need to remove oldest data. Problem is, I can't really accept the disruption it would take to move the massive bulk of data "up" the file, like normal - lock the file for an extended period of time just to rewrite it (plus this being a flash medium, it would cause unnecessary wear to the flash). Probably the easiest way would be

Get the drive letter from a path string or FileInfo

佐手、 提交于 2019-12-30 01:40:08
问题 This may seem like a stupid question, so here goes: Other than parsing the string of FileInfo.FullPath for the drive letter to then use DriveInfo("c") etc to see if there is enough space to write this file. Is there a way to get the drive letter from FileInfo? 回答1: FileInfo f = new FileInfo(path); string drive = Path.GetPathRoot(f.FullName); This will return "C:\". That's really the only other way. 回答2: Well, there's also this: FileInfo file = new FileInfo(path); DriveInfo drive = new

NodeJS Copying File over a stream is very slow

独自空忆成欢 提交于 2019-12-30 00:36:10
问题 I am copying file with Node on an SSD under VMWare, but the performance is very low. The benchmark I have run to measure actual speed is as follows: $ hdparm -tT /dev/sda /dev/sda: Timing cached reads: 12004 MB in 1.99 seconds = 6025.64 MB/sec Timing buffered disk reads: 1370 MB in 3.00 seconds = 456.29 MB/sec However, the following Node code that copies file is very slow, evne teh consequent runs do not make it faster: var fs = require("fs"); fs.createReadStream("bigfile").pipe(fs

How to move all files with specific extension from all subdirectories to their parent using CMD?

匆匆过客 提交于 2019-12-29 20:33:22
问题 Folder c:\folder1 contains subfolder1 , subfolder2 , etc.. These subdirectories hold .pdf and .db files. How can all the .pdf files be moved to c:\folder1 using the Windows command interpreter? 回答1: This worked for me: for /r "c:\source_directory\" %%x in (*.pdf) do move "%%x" "c:\target_directory\" This command will copy recursively al pdf files from source to target directory using cmd in windows 7 - tested and works. Hope it helps. 回答2: The outer for loop lists the sub-directories in the

How to read from a specific line from a text file in VHDL

匆匆过客 提交于 2019-12-29 09:04:29
问题 I am doing a program in VHDL to read and write data. My program has to read data from a line, process it, and then save the new value in the old position. My code is somewhat like: WRITE_FILE: process (CLK) variable VEC_LINE : line; file VEC_FILE : text is out "results"; begin if CLK='0' then write (VEC_LINE, OUT_DATA); writeline (VEC_FILE, VEC_LINE); end if; end process WRITE_FILE; If I want to read line 15, how can I specify that? Then I want to clear line 15 and have to write a new data

How to read from a specific line from a text file in VHDL

老子叫甜甜 提交于 2019-12-29 09:04:13
问题 I am doing a program in VHDL to read and write data. My program has to read data from a line, process it, and then save the new value in the old position. My code is somewhat like: WRITE_FILE: process (CLK) variable VEC_LINE : line; file VEC_FILE : text is out "results"; begin if CLK='0' then write (VEC_LINE, OUT_DATA); writeline (VEC_FILE, VEC_LINE); end if; end process WRITE_FILE; If I want to read line 15, how can I specify that? Then I want to clear line 15 and have to write a new data

Files.find() with BiPredicate in Kotlin

≡放荡痞女 提交于 2019-12-29 08:53:07
问题 I want to find all files in files tree. In Java I'd write something like: try(Stream<Path< paths = Files.find(startingPath, maxDepth, (path, attributes) -> !attributes.isDirectory())) { paths.forEach(System.out::println); } But I am using kotlin, and came up with this: Files.find(startingPath,maxDepth, { (path, basicFileAttributes) -> !basicFileAttributes.isDirectory()} ).use { println(it) } However, this gives me error: Cannot infer a type for this parameter. Please specify it explicitly.