| | |
not sure why program crashes
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Solved Threads: 0
hi, I am doing a lab assignment for my C++ class and it wants us to use serveral pointer indirections for each variable. The program runs but then crashs and it seems to occur during the second iteration of a for loop in the arrayGet function. I'm not sure why, something to do with "Access violation reading location".
The program reads from a file and fills up the vector then copies the vector to a array and then prints out both variables.
Any help would be great, thanks
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <fstream> #include <vector> using namespace std; bool vectorGet(vector<string> ****); bool arrayGet(string ***, vector<string> ****); int main() { vector<string> ****p; string ***r; p = new vector<string> ***; r = new string **; vectorGet(p); for(int x = 0; x < (*(*(*p)))->size(); x++) { cout << (*(*(*(*p))))[x] <<endl; } arrayGet(r, p); for(int y = 0; y < (*(*(*p)))->size(); y++) { cout << *(*r)[y] <<endl; } delete *(*(*p)); delete *(*p); delete *p; delete p; delete *(*r); delete *r; delete r; } bool vectorGet(vector<string> ****p) { *p = new vector<string> **; *(*p) = new vector<string> *; *(*(*p)) = new vector<string>; string temp; fstream document("TopicAin.txt"); while(!document.eof() ) { getline(document, temp); (*(*(*p)))->push_back(temp); } return true; } bool arrayGet(string ***r, vector<string> ****p) { *r = new string *; *(*r) = new string[(*(*(*p)))->size()]; for(int y = 0; y < (*(*(*p)))->size(); y++) { *(*r)[y] = (*(*(*(*p))))[y]; //crash happens here } return true; }
The program reads from a file and fills up the vector then copies the vector to a array and then prints out both variables.
Any help would be great, thanks
Last edited by Narue; Jan 15th, 2008 at 6:05 pm.
![]() |
Similar Threads
- newbie: lock file so only one instance of program runs (C++)
- Program crahses: caused by infections? Please help (Viruses, Spyware and other Nasties)
- problems with a C++ program can't seem to compile it (C++)
- Program Crashing PT2 (C++)
- Program crashing (C)
- Help on random freezing and strange program behavior! (Viruses, Spyware and other Nasties)
- Pause the Program (C++)
- help with sorting program (C++)
- WIn XP Crashes (Windows NT / 2000 / XP)
- Linux crashing on me when trying to configure network (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: Array of words
- Next Thread: C and C++ Timesaving Tips
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





