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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:31:08+00:00 2026-06-06T03:31:08+00:00

Well, Here is the C++ code I’ve got here and cant compile #include <iostream>

  • 0

Well, Here is the C++ code I’ve got here and cant compile

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int n = 900;
class City{
string name;
double area;
int count, roads;


public:
City() {}
City(string a, double b, int c, int d ) { a=name; b=area; c=count; d=roads;}
string getname() {return name;}
double getarea() {return area;}
int getcount() {return count;}
int getroads() {return roads;}
friend ostream& operator << (ostream& , City& );
friend istream& operator >> (istream& , City& );

};

ostream& operator << (ostream& out, City& a) {
out<<"name "<<a.name<<", area "<<a.area<<", count "<<a.count<< ", roads   "<<a.roads<<endl;
return out; 
 }
istream& operator >> (istream& in, City& a) {
in>>a.name>>a.area>>a.count>>a.roads;
return in;
   }
void fill(int arr[], int size){
ifstream ifs("cities.txt.");
for (int i=0;i<size;i++) 
    ifs>>arr[i];
  }


 void func(City* arr){
ofstream ofs("density.out");
for(int i=0;i<n;i++){
    if(arr[i].getcount()/arr[i].getarea()>1000)
        ofs<<arr[i];
}
  }

  int main(){
City* hm;
hm = new City[n];
fill(hm, n);
func(hm);
system ("pause");
return 0;
 }

here is the error I get while compiling:

error C2664: ‘fill’ : cannot convert parameter 1 from ‘City *’ to ‘int
[]’

somehow I see that, it says something is wrong with the Class ‘City *” and int[] array, but can’t figure out. I change the ‘int’ with double but same prob.
that’s problem, otherwise it seems a simple array filling function from file.
any idea what’s wrong with it?

So, how would

void fill(City& arr, int size)
‘s body would like?

  • 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-06T03:31:09+00:00Added an answer on June 6, 2026 at 3:31 am

    void fill(int arr[], int size) means that you need to pass an array of int to fill. However, you are passing it an instance of City, specifically hm in your main.

    I am assuming that you are trying to read in a list of City descriptions from cities.txt (and thus have appropriate stream extraction/insertion operators). Change the signature of fill to accept a pointer to City objects so that you can fill in an array of City objects and not ints.

    void fill(City *arr, int size); 
    

    Make sure that the argument you pass to fill in main is a properly allocated array of City objects of size at least sz where sz is what you pass in as the second parameter. Keep in mind to call delete [] to free this array that you create.

    A more idiomatic approach would be to use vector<City> so that you don’t have to worry about memory management issues. Your modified fill signature would then be:

    void fill(std::vector<City>& c); // note we no longer need the second argument
    

    You will need to #include <vector> in order to be able to use vector<City> though.

    Finally, to take advantage of RVO, simply return a vector<City> by value instead of passing it in as a parameter. So, you’d do something like:

    std::vector<City> fill(); // cleaner, faster
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, I'm using GroupLayout to place components. Here is a code. groupLayout.setHorizontalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup()
Here is my code (well, some of it). The question I have is, can
Well, I'm gonna be pretty straightforward here, I just have a piece of code
Some time ago, people here helped me very well with code. Now I'm tasked
Well im here because i have a problem. i have code that was created
I've looked at the code here as well as the code here but I
Here's the situation, I've got a C++ codebase which is using a recent GCC
Well here is the API I'm trying to use: http://www.hotelscombined.com/api/LiveRates.asmx?op=HotelSearch Here is the code
(Note: The code here is Monotouch/C#, however Objective-C Answers are welcome!) Im using AVPlayer
I followed the code here: http://drumcoder.co.uk/blog/2010/apr/09/django-reset-password/ as well as here: http://shrenikp.webs.com/apps/blog/entries/show/7133721-implement-forgot-password-on-customer-ui- and here: http://blog.montylounge.com/2009/07/12/django-forgot-password/

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.