ifstream

ifstream not opening file

旧时模样 提交于 2019-12-22 09:29:51
问题 In this function i am trying to open a file that contains a set of characters that i want to assign to my matrix array, however whenever i run this program the console displays an error that says that the file is not open. Another question, if i add that file to my resource folder how do i specify to access that file and not the one that i have in the root of my hard drive? ifstream readSecondMap("C:\\map_2.txt", ifstream::in); void Stage::populateStage(ifstream &myStage, char (&myArray)

fstream ifstream I don't understand how to load a data file into my program

℡╲_俬逩灬. 提交于 2019-12-22 08:32:55
问题 My professor is very smart but expects complete noobs like me to just know how to program c++. I don't understand how the fstream function works. I will have a data file with three columns of data. I will have to determine with a logarithm whether each line of data represents a circle, rectangle or triangle - that part is easy. The part I don't understand is how the fstream function works. I think I: #include < fstream > then I should declare my file object? ifstream Holes; then I open it:

clang 3.3/Xcode & libc++: std::getline does not read data after calling ifstream::clear()

≯℡__Kan透↙ 提交于 2019-12-22 07:06:40
问题 The following program demonstrates an inconsistency in std::getline behavior between libc++ and libstdc++ (using clang3.3). The program opens the file testfile, reads it until eof, then clears the error bits using ifstream::clear and tries to read from the same filehandle again to see if new data was appended to the file. #include <fstream> #include <iostream> #include <unistd.h> using namespace std; int main() { ifstream* file = new ifstream("testfile"); if ( ! file->is_open() ) { cout <<

How to read entire stream into a std::vector?

对着背影说爱祢 提交于 2019-12-21 17:09:51
问题 I read an answer here showing how to read an entire stream into a std::string with the following one (two) liner: std::istreambuf_iterator<char> eos; std::string s(std::istreambuf_iterator<char>(stream), eos); For doing something similar to read a binary stream into a std::vector , why can't I simply replace char with uint8_t and std::string with std::vector ? auto stream = std::ifstream(path, std::ios::in | std::ios::binary); auto eos = std::istreambuf_iterator<uint8_t>(); auto buffer = std:

How to open a file with relative path in C++?

可紊 提交于 2019-12-21 04:55:19
问题 I am writing test cases right now and I created some test files which I try to read. The absolute path is: /home/user/code/Project/source/Project/components/Project/test/file.dat but testing with an absolute path is bad for obvious reasons. So I try to convert the absolute path into a relative one and I don't know why it doesn't work. I created a file with the relative path findme.dat and I found it in /home/user/code/Project/build/source/Project/components/Project/test/findme.dat so I

Why am I getting this ifstream error?

无人久伴 提交于 2019-12-20 16:14:39
问题 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>

Why am I getting this ifstream error?

烈酒焚心 提交于 2019-12-20 16:13:35
问题 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>

Why am I getting this ifstream error?

旧巷老猫 提交于 2019-12-20 16:13:27
问题 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>

Why are extra parenthesis in file read function?

岁酱吖の 提交于 2019-12-20 14:12:51
问题 I understand that the following code (from here) is used to read the contents of a file to string: #include <fstream> #include <string> std::ifstream ifs("myfile.txt"); std::string content( (std::istreambuf_iterator<char>(ifs) ), (std::istreambuf_iterator<char>() ) ); However, I don't understand why such seemingly redundant parentheticals are required. For example, the following code does not compile: #include <fstream> #include <string> std::ifstream ifs("myfile.txt"); std::string content

Using a var from a text file

依然范特西╮ 提交于 2019-12-20 07:52:37
问题 My problem is that I would like to use the function launched by the keyword received in carac from a text file, and use the string right after carac in this function that is in an other file included but I have no idea how to do it. for(std::string carac; fichier>>carac;) { auto found = _map.find(carac); if(found != _map.end() { found->second(); pile_double.afficher(); // Pile is the french word for a LIFO Queue, afficher is the one for display } } 回答1: If I'm understanding correctly all you