Filling vector with structure

Apr 20, 2015 at 2:30pm
Hi guys can u help me? I have created vector,structure as u can see but I have issues w/ filling the vector...My task is to make a vector where user have to enter name,area,inhabitants. Much thanks for your help!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct CITY{
	string name;
	double area;
	int inhabitants;
};
int _tmain(int argc, _TCHAR* argv[])
{
	int N = 0;
	cout << "Enter number of which represents counts of towns:";
	cin >> N;
	string name;
	vector<CITY> town;
        CITY temp;
	town.reserve(N)
	for (int i = 1; i <= N; i++){
		temp.name->assign(getline(cin,name));
	
	}
	system("pause");
	return 0;
}
Last edited on Apr 20, 2015 at 2:34pm
Apr 20, 2015 at 2:53pm
Perhaps you need to study the documentation for getline() to see what this function actually returns?

Next I really don't see where you're trying to fill in any vector. Also beware that vector.reserve() just increases capacity, but doesn't alter the size of the vector.


Topic archived. No new replies allowed.