[Solved] Exception thrown: read access violation. **dynamicArray** was 0x1118235. occurred

[ad_1] There are multiple issues with your program. Let me list all of them one by one. As mentioned in one of the comments, You are immediately deallocating memory just after you allocated it. Definitely this will result in a segmentation fault or memory access violation when you access deallocated memory. When you allocate the … Read more

[Solved] std::vector push_back results in access Violation

[ad_1] Dict* test = (Dict*)malloc(sizeof(Dict)); does not do what you think it does. malloc allocates a block of memory, but does not initialize it. So later on, when you call test->nodes.push_back, you’re calling into uninitialized memory. Undefined behavior. In your case, it crashes. The solution here is allocate test with new, which will initialize both … Read more

[Solved] c++, reading string from file, segmentation fault

[ad_1] I’ve read Your answers, search in books and changed whole idea of reading-writing 🙂 Now when I write I use: int stringSize=text.length()*sizeof(char); file.write(reinterpret_cast<char*>(&stringSize),sizeof(stringSize)); file.write(text.c_str(),stringSize); And when I read I use: int stringSize=0; string text; plik.read(reinterpret_cast<char*>(&stringSize),sizeof(stringSize)); char * tempCharArray = new char[stringSize+1]{}; plik.read(tempCharArray,stringSize); text=tempCharArray; delete [] tempCharArray; No segmentation fault/access violation since then 🙂 I … Read more