ifstream

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

旧城冷巷雨未停 提交于 2019-12-02 05:25:39
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 42 6C 6F 63 6B 73 00 00 80 00 07 FF 39 01 FF 03 03 02 FF 3F 00 07 FF 39 01 FF 03 03 02 FF 3F 00 07 FF

Having trouble with fstream in Xcode

故事扮演 提交于 2019-12-02 03:29:15
I'm having trouble validating the existence of REGISTER.txt for input purposes in a function (see below). My understanding is that if the file doesn't exist, then the file won't be opened and the file stream variable (inData) will be false. Thus, I can use that variable in an if/else statement to verify whether or not it opened. But even though REGISTER.txt is in the same directory as my .cpp file, my code still says that it wasn't opened. Here's the thing though. When I run the same exact code in Dev-C++ compiler, it works fine and the file is found. Now, I understand compilers are different,

Failing to read file loaded with ifstream

∥☆過路亽.° 提交于 2019-12-02 03:08:10
问题 void bot_manager_item::create_games() { games.clear(); std::ifstream paths_in("C:\\Users\\bill hank\\Documents\\bot_plugins\\directory_listing.txt", std::ios::in); while (paths_in.good()) { send_message("The path was good."); char q[5000]; paths_in.getline(q, 5000); send_message(q); games.push_back(qanda(q)); } paths_in.close(); } The file I'm loading exists, what else might be wrong? paths_in.good keeps failing. Edit: I figured it out. Wow am I annoyed by the answer to this. Basically

Failing to read file loaded with ifstream

馋奶兔 提交于 2019-12-02 02:31:49
void bot_manager_item::create_games() { games.clear(); std::ifstream paths_in("C:\\Users\\bill hank\\Documents\\bot_plugins\\directory_listing.txt", std::ios::in); while (paths_in.good()) { send_message("The path was good."); char q[5000]; paths_in.getline(q, 5000); send_message(q); games.push_back(qanda(q)); } paths_in.close(); } The file I'm loading exists, what else might be wrong? paths_in.good keeps failing. Edit: I figured it out. Wow am I annoyed by the answer to this. Basically Windows lets you say whether you want to show file extensions or not. This windows installation is set to say

Reading binary data into struct with ifstream

时光总嘲笑我的痴心妄想 提交于 2019-12-01 23:02:17
问题 I'm trying to read binary data from a file using ifstream. Specifically, I'm trying to populate this "Header" struct with data read from a file: struct Header { char id[16]; int length; int count; }; Now, if I read the file in this way, the result is exactly what I want: input.read((char*)&hdr, sizeof(hdr)); But if I instead read each variable of the struct manually, the results are gibberish: input.read((char*)&hdr.id, sizeof(hdr.id)); input.read((char*)&hdr.length, sizeof(hdr.length));

Reading binary data into struct with ifstream

岁酱吖の 提交于 2019-12-01 20:45:03
I'm trying to read binary data from a file using ifstream. Specifically, I'm trying to populate this "Header" struct with data read from a file: struct Header { char id[16]; int length; int count; }; Now, if I read the file in this way, the result is exactly what I want: input.read((char*)&hdr, sizeof(hdr)); But if I instead read each variable of the struct manually, the results are gibberish: input.read((char*)&hdr.id, sizeof(hdr.id)); input.read((char*)&hdr.length, sizeof(hdr.length)); input.read((char*)&hdr.count, sizeof(hdr.count)); My question is, what is happening here that makes these

Program crashes after opening file [closed]

China☆狼群 提交于 2019-12-01 20:21:04
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I need to read values from a file into my program. The file is opening successfully, but then it crashes right away. Is there something wrong with my

Program crashes after opening file [closed]

不问归期 提交于 2019-12-01 18:54:54
I need to read values from a file into my program. The file is opening successfully, but then it crashes right away. Is there something wrong with my code? void createList(intNode*& intList) { intNode* lastInt; //points to last integer in file lastInt = NULL; int fileInt; //int read from input file ifstream intInputFile; intInputFile.open("intInput.txt"); if (intInputFile.is_open()) { cout << "intInput.txt open successful" << endl; } else { cout << "intInput.txt open unsuccessful" << endl; } intInputFile >> fileInt; while(!intInputFile.eof()) { intNode* anotherInt; anotherInt = new intNode; if

ifstream::open() function using a string as the parameter [duplicate]

点点圈 提交于 2019-12-01 17:43:34
问题 This question already has an answer here : No matching function - ifstream open() (1 answer) Closed 4 years ago . I'm trying to make a program that asks for the file that they user would like to read from, and when I try to myfile.open(fileName) I get the error: "no matching function for call to std::basic_ifstream<char, std::char_traits<char> >::open(std::string&)' " at that line. string filename; cout<<"Enter name of file: "; cin>>filename; ifstream myFile; myFile.open(filename); //where

How to read the 6th character from the end of the file - ifstream?

时光怂恿深爱的人放手 提交于 2019-12-01 14:23:40
void maintainFileName () { std :: ifstream myfile; myfile.open ("zoomLevels.txt"); if (myfile.is_open ()) { // Move to end of the file, myfile.seekg (0, std::ios::end); // and then six characters back to pick up the last file number. myfile.seekg (6, std::ios::beg); int len = 1; char *t = new char[len]; myfile.read(t, len); qDebug () << "\nt: " << *t << "\n"; } else { qDebug () << "\nsorry"; } } The file contains this: 78.8115,29.582,1,01.rda 78.8115,29.582,2,02.rda 76.3671,30.2201,1,11.rda 76.3671,30.2201,2,12.rda 78.1908,30.3007,1,01.rda 78.1908,30.3007,2,02.rda 77.3284,29.1415,1,01.rda 77