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

  • SEARCH
  • Home
  • 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 7553631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:06:47+00:00 2026-05-30T11:06:47+00:00

I am trying to make multi-weighted graphs. Input is to be made in following

  • 0

I am trying to make multi-weighted graphs.
Input is to be made in following way

  1. Firstly user number of vertex user want and
  2. The ith line of a programmer’s map contains details of the vertex
    directly accessible from room i . for ex

5
a 2 // (vertex 1 is connected to vertex 2 by edge having weight ‘a’)
t 5 r 4 // (vertex 2 is connected to vertex 4 an by edge having weight ‘t’and’r’)
a 4
r 2 t 3
b 5 i 5 o 5

#include <iostream>
#include <vector>
#include <sstream>
using namespace std;
struct maps{
 vector<char> weight;   //for storing multiple-edge and self-loop![enter image description here][1]
};
void input_edge(int n,maps m[10][10])
{
 std::string user_input;
 std::istringstream iss(user_input);
 char letter;// for making tokens 
 int index; // for making tokens
 int i;
 for(i=1;i<=n;i++)
{ std::getline(std::cin, user_input);
  while (iss >> letter >> index)
  m[i][index].weight.push_back(letter);
}
}
int main()
{ int n;//no.of vertex user want to make graph
  cin>>n;
  cin.ignore(1000,'\n');
  maps m1[10][10];
  input_edge(n,m1);
  int i,j; 
  for(i=1;i<=n;i++)
  for(j=1;j<=n;j++)
  {cout<<"no of edge between vertex"<<i<<' '<<"and"<<' '<<j<<':'<<m1[i][j].weight.size()<<endl;}//to find no of edge between 2 vertex
} 

but i am getting incorrect outputs.please tell how to fix it..

[1]: https://i.stack.imgur.com/sTgeD.png

  • 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-30T11:06:49+00:00Added an answer on May 30, 2026 at 11:06 am

    You don’t quite understand the use of istringstream. On this line std::istringstream iss(user_input); you fill in all the content you will read from the input string stream. From then on nevermind how many things you read in std::getline(std::cin, user_input); you never change the contents of iss, meaning that the input string stream will never serve you anything but nulls. Change your code like that:

    void input_edge(int n,maps m[10][10])
    {
     std::string user_input;
    
     char letter;// for making tokens 
     int index; // for making tokens
     int i;
     for(i=1;i<=n;i++)
    { std::getline(std::cin, user_input);
      std::istringstream iss(user_input);
      while (iss >> letter >> index)
      m[i][index].weight.push_back(letter);
    }
    

    And see if there is any difference.

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

Sidebar

Related Questions

I am trying to make a multi user login system for my java program,
I'm trying to make my C# application multi threaded because sometimes, I get an
Trying to make a MySQL-based application support MS SQL, I ran into the following
I am trying to make a multi-dimensional array of characters in ruby, and this
I'm trying to make a multi instance engine in C++ with a wrapper for
Have an options table that i'm trying to make multi lingual with an English
I am trying to make a multi-table query that I am not quite sure
I'm trying to make a button in Flash Builder 4.5 that is multi-lined (specific
I'm trying to make a multi-countdown on a page, which looks like : <table>
I am trying to make a multi-textured point sprite for an iphone application using

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.