Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7743487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:32:50+00:00 2026-06-01T09:32:50+00:00

I am trying to write some data from these vectors onto text files. When

  • 0

I am trying to write some data from these vectors onto text files. When I run the code it returns a run time error. Category, Product, Cart, Customerand Address are all struct with members that each get_member returns.

ofstream write_cats;
    write_cats.open("catprd.dat", ios::out, ios::trunc);
    vector<Category>::iterator i;
    write_cats << cats.size() << endl;
    for (i = cats.begin(); i < cats.end(); i++) {
        write_cats << i -> get_catid() << '\t';
        }
    vector<Product>::iterator j;
    write_cats << prods.size() << endl;
    for (j = prods.begin(); j < prods.end(); j++) {
        write_cats << j -> get_prodid() << '\t';
        write_cats << j -> get_prodprice() << endl;
        }
    write_cats.close();

    ofstream write_carts;
    write_carts.open("carts.dat", ios::out, ios::trunc);
    vector<Cart>::iterator k;
    write_carts << carts.size() << endl;
    for (k = carts.begin(); k < carts.end(); k++) {
        write_carts << k -> get_cartid() << '\t';
        write_carts << k -> get_day() << endl;
        }
    vector<Cart_item>::iterator l;
    write_carts << cart_items.size() << endl;
    for (l = cart_items.begin(); l < cart_items.end(); l++) {
        write_carts << l -> get_cartitemid() << '\t';
        write_carts << l -> get_qty() << endl;
        }
    write_carts.close();

    ofstream write_custs;
    write_custs.open("custs.dat", ios::out, ios::trunc);
    vector<Customer>::iterator m;
    vector<Address>::iterator n;
    write_custs << custs.size() << endl;
    for (m = custs.begin(); m < custs.end(); m++) {
        write_custs << m -> get_cust_id() << '\t';
        write_custs << n -> get_zip_code() << endl;
        }
    write_custs.close();

Returns run time error “Vector iterator not dereferencable”

Here is how struct Address looks like:

using namespace std;
#pragma once
#include <string>

struct Address {

public:

int get_st_number() const{return st_number;} 
int get_zip_code() const{return zip_code;} 
string get_st_name() const{return st_name;} 



Address(){}                                 
Address (int num, string name, int zip) 
    : st_number(num), st_name(name), zip_code(zip) {}

private:
int st_number;
int zip_code;
string st_name;


};

and struct Customer:

struct Customer {
public:

Address get_address() const{return addr;} 
int get_cust_id() const{return cust_id;}  customer id
string get_name() const{return cust_name;} 
Customer (int id, string n, Address a)  
    : cust_id(id), cust_name(n), addr(a) {}


string display_addr() const {
    std::cout<<setw(15)<<cust_name<<" ";
    std::cout<<setw(15)<<cust_id<<" ";

    return string();
}



private:

int cust_id;
string cust_name;
Address addr;           
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:32:51+00:00Added an answer on June 1, 2026 at 9:32 am

    you forget to initialize vector<Address>::iterator n;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some Haskell code in which there are multiple data types,
I'm trying to write some code to extract Exif information from a JPG. Exif
I'm trying to write some code using pure SQL using ASP.NET MVC. I assume
I'm trying to write some code to Hide columns if the first 3 characters
I'm trying to write some code to remove the first N characters in a
I am trying to write some code to return an array in C#, but
I am trying to write some code that that will draw the line which
Following on from a previous question, I'm trying to clean up some data where
I'm trying to write some Java code for a set of enum classes. Each
I'm trying to write some computationally intensive code for Windows x64 target, with SSE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.