User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,879 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,170 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums

Class with use of <vector>

Join Date: Sep 2004
Posts: 410
Reputation: JoBe is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
JoBe's Avatar
JoBe JoBe is offline Offline
Posting Pro in Training

Class with use of <vector>

  #1  
May 24th, 2005
Hello ladies and gents,

Wanted to make this part of an exercise in wich I enter each time two integers into an array for wich I have to use STL container vector.

Ive got this sofar, but getting an error message when I entered two numbers and the exe shuts down? I'm almost certain it's got to do with the
while (cin>> x >>" ">> y, !cin.fail())

But, not sure about it and even if, don't know how to solve it?

What Ive got sofar in total is this:
#include <iostream>
#include <vector>

using namespace std;

class point
{
private:
	int x, y, z;

public:
	point (int xx = 0, int yy = 0, int zz = 0): x (xx), y (yy), z (zz) {}

	vector<int> s, t;

	void numbers()
	{
		while (cin>> x >>" ">> y, !cin.fail())
		{
			s.push_back(x);
			s.push_back(y);
		}

	}

	void print()
	{
		int n = s.size();

		for (z = 0; z < n; z++)
			cout<< s[z] <<endl;
	}
};

int main()
{
	point u;

	cout<<"Type twee integere getallen in per keer: "<<endl;

	u.numbers();

	u.print();

	cin.get();

	return 0;
}

Could someone please point me in the right direction, thank you
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 4:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC