•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,218 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,208 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 737 | Replies: 1 | Solved
![]() |
•
•
Join Date: Jan 2008
Posts: 2
Reputation:
Rep Power: 0
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
#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 5:05 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
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 / 2003)
- 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


Linear Mode