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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:04:44+00:00 2026-06-11T01:04:44+00:00

Here is the code: #include <string> #include <iostream> #include <vector> #include <algorithm> using namespace

  • 0

Here is the code:

#include <string>
#include <iostream>

#include <vector>
#include <algorithm>

using namespace std;

struct Pair{
  string name;
  double val;
};

vector<Pair> pairs;

double& value(const string& s)
{
  for(int i=0; i < pairs.size(); i++)
    if(s == pairs[i].name)
      return pairs[i].val;

  Pair p = {s, 0};
  pairs.push_back(p);

  return pairs[pairs.size() - 1].val;
}

int main()
{
  string buf;
  while(cin>>buf) value(buf)++;

  for(vector<Pair>::const_iterator p = pairs.begin(); p != pairs.end(); ++p)
    cout << p->name << ": " << p->val << '\n';
  return 0;
}

The compiler always complains that Line (Pair p = {s, 0};) is wrong:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
….\cpp\TEST.CPP:
Warning W8012 ….\cpp\TEST.CPP 18: Comparing signed and unsigned values in fun
ction value(const string &)
Error E2291 ….\cpp\TEST.CPP 22: } expected in function value(const string &)
Error E2034 ….\cpp\TEST.CPP 22: Cannot convert ‘const string’ to ‘Pair’ in fu
nction value(const string &)
Error E2141 ….\cpp\TEST.CPP 22: Declaration syntax error in function value(co
nst string &)
Error E2139 ….\cpp\TEST.CPP 22: Declaration missing ; in function value(const
string &)
Warning W8070 ….\cpp\TEST.CPP 22: Function should return a value in function
value(const string &)
Warning W8004 ….\cpp\TEST.CPP 22: ‘p’ is assigned a value that is never used
in function value(const string &)
Error E2190 ….\cpp\TEST.CPP 22: Unexpected }
Error E2238 ….\cpp\TEST.CPP 23: Multiple declaration for ‘pairs’
Error E2344 ….\cpp\TEST.CPP 14: Earlier declaration of ‘pairs’
Error E2141 ….\cpp\TEST.CPP 23: Declaration syntax error
Error E2040 ….\cpp\TEST.CPP 25: Declaration terminated incorrectly
Error E2190 ….\cpp\TEST.CPP 26: Unexpected }
* 10 errors in Compile *

  • 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-11T01:04:46+00:00Added an answer on June 11, 2026 at 1:04 am

    The code compiles with only a warning using an up-to-date compiler (GCC 4.6.3). Your compiler must not be fully compliant.

    For a compilation with GCC 4.3.4, see here.

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

Sidebar

Related Questions

Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
here is my code for xor linked list implementation #include<iostream> using namespace std; struct
#include <boost/algorithm/string.hpp> #include <vector> #include <iostream> #include <string> using namespace std; using namespace boost;
Here is my code: #include <iostream> #include <stdlib.h> #include <fstream> using namespace std; int
here is code #include <iostream> #include <string> #include <algorithm> #include <vector> #include <fstream> #include
Here is the code for sorting a vector of string s #include<iostream> #include <vector>
Here is a code sample. // file temp.cpp #include <iostream> #include <vector> #include <boost/spirit/include/qi.hpp>
Here is the code: #include <iostream> #include <string> #include <map> #include <stdexcept> #include <boost/ptr_container/ptr_vector.hpp>
I have the following code: [test.cpp] #include <mcrypt.h> #include <string> #include <iostream> #include <vector>

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.