Kori 170 Posted September 14, 2018 Share Posted September 14, 2018 Hello Guys, Here is my Mount system via txt ( Serverside ) but i have a little proplem. The txt dont load but i dont know why. Here my char_mount.cpp: #include "stdafx.h" #include "char_mount.h" #include "char.h" #include "log.h" #include <fstream> #include <sstream> std::vector <AddNewMountsStruct> MountObjectList; void LoadNewMounts(const char *fileName) { std::string strdwVnum; std::ifstream File(fileName); if (File.fail()) { sys_err("%s not found", fileName); return; } MountObjectList.clear(); AddNewMountsStruct preload; while (!File.eof()) { File >> strdwVnum; preload.dwVnum = atoi(strdwVnum.c_str()); MountObjectList.push_back(preload); } sys_log(1, "Datei geladen"); } bool AddNewMounts(int dwVnum) { for (unsigned int i = 0; i < MountObjectList.size(); i++){ if (MountObjectList[i].dwVnum == dwVnum){ return true; } } return false; } char_mount.h struct AddNewMountsStruct{ int dwVnum; }; void LoadNewMounts(const char *fileName); bool AddNewMounts(int dwVnum); here the funktion from the main.cpp int main(int argc, char **argv) ) LoadNewMounts("Mounts.txt"); the Mounts.txt looks like 0 // Character DMG 101 // example Mount 102 // example Mount 103 // example Mount Link to comment Share on other sites More sharing options...
Premium Jira 458 Posted September 14, 2018 Premium Share Posted September 14, 2018 use snprintf .. Link to comment Share on other sites More sharing options...
Kori 170 Posted September 14, 2018 Author Share Posted September 14, 2018 Just now, Shelby said: use snprintf .. For What ? thanks for answer Link to comment Share on other sites More sharing options...
Premium Jira 458 Posted September 14, 2018 Premium Share Posted September 14, 2018 for load the file dude, char YourFileName[256+1]; snprintf(YourFileName, sizeof(YourFileName), "yourfilename.txt"); and open it, etc.. Link to comment Share on other sites More sharing options...
Solution Kori 170 Posted September 14, 2018 Author Solution Share Posted September 14, 2018 31 minutes ago, Shelby said: for load the file dude, char YourFileName[256+1]; snprintf(YourFileName, sizeof(YourFileName), "yourfilename.txt"); and open it, etc.. sorry i dont understand you now :/ edit: My new main.cpp function: LoadNewMounts(); char_mounts.h: struct AddNewMountsStruct{ int dwVnum; }; void LoadNewMounts(); bool AddNewMounts(int dwVnum); char_mount.cpp: #include "stdafx.h" #include "locale_service.h" #include "char_mount.h" #include "char.h" #include "log.h" #include <fstream> #include <sstream> using namespace std; std::vector <AddNewMountsStruct> MountObjectList; void LoadNewMounts() { char szFileName[256]; snprintf(szFileName, sizeof(szFileName), "%s/Mounts.txt", LocaleService_GetBasePath().c_str()); string strdwVnum; ifstream File(szFileName); if (!File.is_open()) { fprintf(stderr, "Failed to Load %s/Mounts.txt\n", LocaleService_GetBasePath().c_str()); sys_err("Failed to %s/Mounts.txt", LocaleService_GetBasePath().c_str()); return; } MountObjectList.clear(); AddNewMountsStruct preload; while (!File.eof()) { File >> strdwVnum; preload.dwVnum = atoi(strdwVnum.c_str()); MountObjectList.push_back(preload); } sys_log(1, "Datei geladen"); } bool AddNewMounts(int dwVnum) { for (unsigned int i = 0; i < MountObjectList.size(); i++){ if (MountObjectList[i].dwVnum == dwVnum){ return true; } } return false; } Link to comment Share on other sites More sharing options...
Premium Jira 458 Posted September 14, 2018 Premium Share Posted September 14, 2018 no int dwVnum; DWORD dwVnum; building.h .... Link to comment Share on other sites More sharing options...
Kori 170 Posted September 14, 2018 Author Share Posted September 14, 2018 1 minute ago, Shelby said: no int dwVnum; DWORD dwVnum; the mount is an int the dwVnum is not relevant Link to comment Share on other sites More sharing options...
Forum Moderator Raylee 656 Posted September 14, 2018 Forum Moderator Share Posted September 14, 2018 #closed on request Best regards Raylee 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now