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 3790472
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:19:12+00:00 2026-05-19T12:19:12+00:00

UPDATE: The following code gives me an error Graph.cpp: In function ‘std::ostream& operator<<(std::ostream&, const

  • 0

UPDATE:
The following code gives me an error

Graph.cpp: In function ‘std::ostream&
operator<<(std::ostream&, const
Graph&)’: Graph.cpp:43: error: passing
‘const std::map >,
std::less,
std::allocator > > > >’ as
‘this’ argument of ‘_Tp&
std::map<_Key, _Tp, _Compare,
_Alloc>::operator[](const _Key&) [with _Key = long int, _Tp = std::vector >, _Compare =
std::less, _Alloc =
std::allocator > > >]’
discards qualifiers Graph.cpp:44:
error: passing ‘const std::map >,
std::less,
std::allocator > > > >’ as
‘this’ argument of ‘_Tp&
std::map<_Key, _Tp, _Compare,
_Alloc>::operator[](const _Key&) [with _Key = long int, _Tp = std::vector >, _Compare =
std::less, _Alloc =
std::allocator > > >]’
discards qualifiers make[2]: *
[build/Debug/GNU-MacOSX/Graph.o] Error
1

class Graph {
public:
    Graph();
    Graph(const Graph& orig);
    virtual ~Graph();

    void clear();
    void rgg(lint, double);
    bool is_directed() { return directed; }
    friend ostream& operator<< (ostream&, const Graph&); 


private:
    map< lint, vector<lint> > adjList;
    vector< pair<double, double> > xy;
    double radius;
    MTRand Rand;
    bool directed;
};


void Graph::rgg(lint n, double r) {
    radius = r; directed = false;

    clear(); 

    for(lint i = 0; i < n; i++)
        xy.push_back(pair<double, double>(Rand.rand(), Rand.rand()));
}

ostream& operator<< (ostream& os, const Graph& inGraph) {
    for(lint i = 0; i < inGraph.nodes; i++) {
        os << i << " ";
        if( inGraph.adjList.find(i) != inGraph.adjList.end() ) {
            for(lint idx = 0; idx < (inGraph.adjList[i]).size(); idx++ )
                os << inGraph.adjList[i].at(idx) << " ";

        }
        os << endl;
    }
}

Thank you in advance,

  • 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-05-19T12:19:13+00:00Added an answer on May 19, 2026 at 12:19 pm

    The cause of your problems is that map’s operator[] is a mutable operation (if the key doesn’t exist, it will be added to the map).

    You will have to use the iterator returned from find():

    map< lint, vector<lint> >::const_iterator it = inGraph.adjList.find(i);
    if (it != inGraph.adjList.end();
    for(lint idx = 0; idx < it->size(); idx++ )
        os << it->at(idx) << " ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following javascript code, which loads without error, however the update function
Update: I've added the following code: function TSettingsForm.AppDataPath: string; //CSIDL_APPDATA Individual user Data //CSIDL_COMMON_APPDATA
Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
I have the following query: UPDATE lessonstatus INNER JOIN user ON lessonstatus.user_id = user.user_id
I have an SQL query that takes the following form: UPDATE foo SET flag=true
I would like to update a Windows Forms application to provide the following features:
I need to update a record in a database with the following fields [ID]
I'm trying to get the following SQL statement to work: UPDATE myschema.tableA update_tableA SET
How can I represent the following in XSD. <price-update> <![CDATA[ arbitrary data goes here
I looking for a clarification regarding the pointers. I have compiled the following code

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.