fstream

optimization of sequential i/o operations on large file sizes

£可爱£侵袭症+ 提交于 2019-12-11 09:14:09
问题 Compiler: Microsoft C++ 2005 Hardware: AMD 64-bit (16 GB) Sequential, read-only access from an 18GB file is committed with the following timing, file access, and file structure characteristics: 18,184,359,164 (file length) 11,240,476,672 (ntfs compressed file length) Time File Method Disk 14:33? compressed fstream fixed disk 14:06 normal fstream fixed disk 12:22 normal winapi fixed disk 11:47 compressed winapi fixed disk 11:29 compressed fstream ram disk 10:37 compressed winapi ram disk 7:18

How to access a specific value in a text file using C++

一笑奈何 提交于 2019-12-11 08:46:29
问题 my text file has this structure and this values 15.32 15.00 14.58 14.36 17.85 01.95 15.36 14.58 21.63 25.00 47.11 48.95 45.63 12.00 74.58 52.66 45.55 47.65 15.55 00.23 78.69 each column is a different type of data, the first column is weigh , second is size and so on. the user requests for instance the weight, which would be the first column 15.32 14.58 74.58 and i need to print reg 1 reg 2 reg 3 15.32 14.58 74.58 also, the user can request other column i don't know how i can accomplish this

Ifstream crashes program when opening file

不打扰是莪最后的温柔 提交于 2019-12-11 07:56:19
问题 I've narrowed my code down, and I found the source of the problem, it's when I open a file. The file does exists, and I don't get any warning or errors when compiling. int main(int argc, const char* args[]) { cout << "Wellcome" << endl; cout << args[1]; ifstream exists(args[1]); if(!exists) { printf("FILE NOT FOUND"); return 1; } exists.close(); ifstream* in; in->open(args[1],ios::binary|ios::in); //do stuff in->close(); return 0; } 回答1: You have created a pointer to an ifstream object, but

seekp/g and tellp/g does not work properly

这一生的挚爱 提交于 2019-12-11 07:47:01
问题 Whenever I try to use tellp/g and seekp/g functions on fstream object, and use the fstream::getline(cstr, bufsize) function, it just don't work properly and don't store anything in 'cstr' variable. and it does not report any problem which invalidate the stream like failbit or badbit Sample code: what it does is read it line by line and on each read it jumps to the end of the file and print the next line's offset from the beginning of the file. int main() { // Prepare file fstream f("test.txt"

getline not working with fstream

☆樱花仙子☆ 提交于 2019-12-11 06:59:57
问题 I am trying to use a text file to initialise a struct that will be used to initialise a 2d vector, yes I know it's complicated but there is going to be a lot of data to work with eventually. The problem is with getline, I have used it this way fine in other code but for some reason it's refusing to work here. I keep getting an argument error and template error. Any hints would be very much appreciated. #include <fstream> #include <string> #include <vector> #include <iostream> using namespace

I/O Stream String Manipulation (Correct Cin/cout operators <</>>)

99封情书 提交于 2019-12-11 06:56:22
问题 I came across this question on here and had a further question about the answer give (I can't comment since I'm new to stackoverflow). The guy who answered it seems to be right about replacing << >> for cin and cout . But the problem I'm having is that all the semi-colons won't show up in the new output file. I know that while std::getline(input, command, ';') erases all semicolons, but theyre supposed to be put back with the else statement at the end, but it isn't being replaced when I run

using fstream object created as class member

帅比萌擦擦* 提交于 2019-12-11 06:24:57
问题 I have an fstream object declared in my class like this (just an example): class Asd { public: Asd(); private: std::fstream stream; }; Now when the constructor is called I want to specify the fstream parameters like this Asd::Asd() { this->stream = std::fstream(file, std::fstream::in); } and then use that stream in all class functions that I have, but it doesn't work. One error VS is giving me is: no accessible path to private member declared in virtual base 'std::basic_ios<_Elem,_Traits>' So

ifstream gcount returns 0 on getline string overload

安稳与你 提交于 2019-12-11 05:25:30
问题 I'm finding that gcount on an ifstream object after a call to getline(istream &, string &) returns 0. Is this supposed to be the case? 回答1: Yes, gcount() is supposed to return the number of characters extracted by the last unformatted input operation performed on the object. getline() is listed in the functions supposed to updated gcount() , but it is the member getline() of a stream and not the string getline(). In case of doubt, this link tells it black on white: Behaves as

How to read integer value from file in C++

↘锁芯ラ 提交于 2019-12-11 03:19:52
问题 How can read integer value from file? For example, these value present in a file: 5 6 7 If I open the file using fstream then how I can get integer value? How can read that number and avoid blank space? 回答1: It's really rare that anyone reads a file Byte by Byte ! ( one char has the size of one Byte). One of the reason is that I/O operation are slowest. So do your IO once (reading or writing on/to the disk), then parse your data in memory as often and fastly as you want. ifstream inoutfile;

is it possible to read from a specific character in a line from a file in c++?

久未见 提交于 2019-12-11 03:06:38
问题 Hey all so I have to get values from a text file, but the values don't stand alone they are all written as this: Population size: 30 Is there any way in c++ that I can read from after the ':'? I've tried using the >> operator like: string pop; inFile >> pop; but off course the whitespace terminates the statement before it gets to the number and for some reason using inFile.getline(pop, 20); gives me loads of errors because it does not want to write directly to string for some reason.. I don't