fstream

What is the difference between flush() and sync() in regard to fstream buffers?

女生的网名这么多〃 提交于 2019-12-03 05:31:49
I was reading the cplusplus.com tutorial on I/O . At the end, it says fstream buffers are synchronized with the file on disc Explicitly, with manipulators: When certain manipulators are used on streams, an explicit synchronization takes place. These manipulators are: flush and endl. and Explicitly, with member function sync(): Calling stream's member function sync(), which takes no parameters, causes an immediate synchronization. This function returns an int value equal to -1 if the stream has no associated buffer or in case of failure. Otherwise (if the stream buffer was successfully

Why am I getting this ifstream error?

六月ゝ 毕业季﹏ 提交于 2019-12-03 04:15:26
Implicit instantiation of undefined template 'std::basic_ifstream<char,std::char_traits<char>>' #ifndef MAPPER_H #define MAPPER_H #include <iostream> #include <string> #include <vector> #include "KeyValue.h" #include "Parser.h" using namespace std; class Mapper { public: Mapper(ifstream& infile); ~Mapper(void); void loadTokens(); void showTokens(); void map(); void printMap(); void printMap(string map_fileName); private: ifstream inFile; //<-- is where the error is happening vector<string> tokens; vector<KeyValue> map_output; Parser* parser; }; #endif I've even tried putting std::ifstream and

C++: What is a stream

前提是你 提交于 2019-12-03 02:59:21
问题 I have been hearing about stream, more specifically file streams. So what are they? Is it something that has a location in the memory? Is it something that contains data? Is it just a connection between a file and an object? Any help would be appreciated 回答1: The term stream is an abstraction of a construct that allows you to send or receive an unknown number of bytes. The metaphor is a stream of water. You take the data as it comes, or send it as needed. Contrast this to an array, for

Why am I getting this ifstream error?

匿名 (未验证) 提交于 2019-12-03 02:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Implicit instantiation of undefined template 'std::basic_ifstream<char,std::char_traits<char>>' #ifndef MAPPER_H #define MAPPER_H #include <iostream> #include <string> #include <vector> #include "KeyValue.h" #include "Parser.h" using namespace std; class Mapper { public: Mapper(ifstream& infile); ~Mapper(void); void loadTokens(); void showTokens(); void map(); void printMap(); void printMap(string map_fileName); private: ifstream inFile; //<-- is where the error is happening vector<string> tokens; vector<KeyValue> map_output; Parser* parser;

Cannot use ifstream in Xcode

匿名 (未验证) 提交于 2019-12-03 02:35:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am new to C++ and have researched this everywhere and cannot seem to figure out how to compile this and have not idea why. It works in visual C++ but not Xcode. The error seems to be on the input stream. Any suggestions? Error reads - "Implicit instantiation of undefined template 'std::_basic_ifstream >' #include <iostream> #include <iostream> #include <string> using namespace std; int main() { cout << "The file is providing the data."; ifstream myFile("/Users/me/Desktop/somewords.txt"); // * error int i; string s; double d; myFile >> i >>

std::ifstream buffer caching

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my application I'm trying to merge sorted files (keeping them sorted of course), so I have to iterate through each element in both files to write the minimal to the third one. This works pretty much slow on big files, as far as I don't see any other choice (the iteration has to be done) I'm trying to optimize file loading. I can use some amount of RAM, which I can use for buffering. I mean instead of reading 4 bytes from both files every time I can read once something like 100Mb and work with that buffer after that, until there will be no

How to clear exception mask in ifstream?

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I set the exception mask failbit of an ifstream by doing: #include <iostream> #include <fstream> int main() { try { std::ifstream in("in.txt"); in.exceptions(std::ifstream::failbit); } catch (std::ios_base::failure &fail) { // handle exception here } } Is there any way I can clear or restore the exception mask? 回答1: Found the solution: std::ifstream::iostate old_state = in.exceptions (); will save the old exception mask. 文章来源: How to clear exception mask in ifstream?

Why does istream_iterator&lt;string&gt;(ifstream(“test.txt”)) cause an error?

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have tried to write a code to read strings from file named "test.txt" and write the strings to standard output. The code below works well: int main() { using namespace std; ifstream file("test.txt"); copy(istream_iterator<string>(file), istream_iterator<string>(), ostream_iterator<string>(cout, " ")); } However, with this modification, the code no longer compiles: int main() { using namespace std; copy(istream_iterator<string>(ifstream("test.txt")), // <-- Error here istream_iterator<string>(), ostream_iterator<string>(cout, " ")); } Why

C++: ios::app doesnt need ios::out in fstream

匿名 (未验证) 提交于 2019-12-03 00:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: i was testing with flags in file stream objects the other day And i did this. fstream binf ( "h.txt" , ios :: app ); binf << "hey" ; With fstream since i didnt use ios::out , the output operation shouldnt have worked , but it does work I noticed that the the output operation works with ios::app only but if i use any other flag without ios::out it doesnt work Can anyone tell me why I was able to output to the file while using only ios::app without ios::out 回答1: Using app implies out . The standard specifies that app and out|app have

No matching function - ifstream open()

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is the part of the code with an error: std::vector loadNumbersFromFile(std::string name) { std::vector numbers; std::ifstream file; file.open(name); // the error is here if(!file) { std::cout > current) { numbers.push_back(current); file.ignore(std::numeric_limits ::max(), '\n'); } return numbers; } And well, I kind of have no idea what is going on. The whole thing compiles properly in VS. However I need to compile this with dev cpp. I commented out the line throwing errors in the code above. The errors are: no matching function for