ifstream

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

Unexpected exception in std::ifstream

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Experimenting with I/O I get an exception where no exception should have been thrown: #include #include int main() { std::ifstream f("/tmp"); std::cout > std::ws) std::cout But the output is: Exception Flags: 0 terminate called after throwing an instance of 'std::ios_base::failure' what(): basic_filebuf::underflow error reading the file Aborted g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 Edit The test is supposed to fail without exception: From 27.5.5.4 basic_ios flags functions void clear(iostate state = goodbit); 4 Postcondition: If rdbuf()!

C++: ifstream as a parameter

半城伤御伤魂 提交于 2019-12-02 20:29:43
问题 I'm trying to make a program that will be able to both create a .txt file and reads from it to create output for tic-tac-toe meant for Linux. However, one of my functions is not initializing it's first parameter, the input stream from the file in question, in order to create the output needed. The function prototype: void loadSquaresFromStream( ifstream inStream, char statusSquare[], int currGame, int row, int column, int mark, int player, int games_Left ); // This function reads from the

how do i read data from textfile and push back to a vector?

徘徊边缘 提交于 2019-12-02 18:11:36
问题 I have a text file, "test.txt" which stored my data as follow, there's a spacing between each delimiter field.. Code: Name: Coy 045: Ted: Coy1 054: Red: Coy2 How do i read this data from file and insert this into a vector? vector <Machine> data; Machine machine void testclass(){ ifstream inFile("test.txt"); if (!inFile){ cout << "File couldn't be opened." << endl; return; } while(!inFile.eof()){ string code,name,coy; getline(inFile,code, ':'); getline(inFile,name, ':'); getline(inFile,coy, ':

I can't get my program to read the values from my input file correctly (2D array)

三世轮回 提交于 2019-12-02 14:01:38
问题 My program reads the values for this incorrectly.. There is the same problem with when I try to get the values from this infile: 14, 14, 8, 0.4, 16, 2.0, 1.7, 7, 4.7, 0.23, 0.44, 290, 350 16, 16, 10, 0.5, 17, 2.2, 1.8, 8, 5.4, 0.27, 0.5, 310, 370 18, 18, 11, 0.5, 18, 2.2, 2.0, 9, 6.0, 0.30, 0.56, 320, 380 20, 20, 12, 0.5, 19, 2.3, 2.2, 9.5, 6.4, 0.32, 0.59, 330, 390 22, 22, 13, 0.5, 20, 2.4, 2.4, 10, 6.7, 0.33, 0.63, 340, 410 24, 24, 14, 0.5, 21, 2.5, 2.5, 11, 7.4, 0.37, 0.69, 350, 420 27, 27

Errors when passing ifstream file through a function

喜你入骨 提交于 2019-12-02 13:01:36
Here is my code: #include <string> #include <iomanip> #include <fstream> #include <iostream> #include <cstring> #include <cctype> using namespace std; // include .h file that holds function ot write header #include "WriteE3RptHdr.h" // declare global constant const int NUM_QTS = 15; // declare struct to hold info on student and answers struct StudRpt { char answers[NUM_QTS]; string firstName; string lastName; char answerKey[NUM_QTS]; string testKey; string testData; }; StudRpt Data; // function prototypes StudRpt StoreAnswerKey(StudRpt Data, ifstream inFile); StudRpt StoreStudData(StudRpt Data

(c++) Read .dat file as hex using ifstream

扶醉桌前 提交于 2019-12-02 11:08:07
问题 This is my first post so sorry if I break any unwritten rules. :P I am a beginner/intermediate programmer and I need help with this program. I am trying to infile/read/ifstream (whatever) a .dat file as HEX into one big string. I don't want to read it as text. I want the hex format so I can search through the string and make changes to it. (Like an automatic hex editor) ex. my file "00000000.dat" is ~7kb in size. In hex editor, the hex look like this: 0A 00 00 0A 00 05 4C 65 76 65 6C 07 00 06

C++: ifstream as a parameter

北战南征 提交于 2019-12-02 10:55:30
I'm trying to make a program that will be able to both create a .txt file and reads from it to create output for tic-tac-toe meant for Linux. However, one of my functions is not initializing it's first parameter, the input stream from the file in question, in order to create the output needed. The function prototype: void loadSquaresFromStream( ifstream inStream, char statusSquare[], int currGame, int row, int column, int mark, int player, int games_Left ); // This function reads from the file 'games.txt' and uses it to update the array // used to output each game. The function head and body:

how do i read data from textfile and push back to a vector?

百般思念 提交于 2019-12-02 10:43:23
I have a text file, "test.txt" which stored my data as follow, there's a spacing between each delimiter field.. Code: Name: Coy 045: Ted: Coy1 054: Red: Coy2 How do i read this data from file and insert this into a vector? vector <Machine> data; Machine machine void testclass(){ ifstream inFile("test.txt"); if (!inFile){ cout << "File couldn't be opened." << endl; return; } while(!inFile.eof()){ string code,name,coy; getline(inFile,code, ':'); getline(inFile,name, ':'); getline(inFile,coy, ':'); data.push_back(machine) } but it seems to have a problem with pushing the data As others have

C++ : How to skip first whitespace while using getline() with ifstream object to read a line from a file?

冷暖自知 提交于 2019-12-02 08:14:31
问题 I have a file named "items.dat" with following contents in the order itemID, itemPrice and itemName. item0001 500.00 item1 name1 with spaces item0002 500.00 item2 name2 with spaces item0003 500.00 item3 name3 with spaces I wrote the following code to read the data and store it in a struct. #include <fstream> #include <iostream> #include <string> #include <cstdlib> #include <iomanip> using namespace std; struct item { string name; string code; double price; }; item items[10]; void