Sign in to follow this  
hothead

got a problem with vector function at()

Recommended Posts

it is supposed to print "the first one 1" "the second one 2" I just fooled around with some code I saw don't know too much about it
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

int main()
{
	vector <int> v1;
	vector <int> v2;
	v1.push_back(1);
	v2.push_back(2);

	const int j = v1.at(0);
	const int i = v2.at(1);

	cout <<"the first one" << j << "\n";
	cout <<"the second one" << i << "\n";

	system("pause");
	return 0;
}
errors:LINK : fatal error LNK1201: error writing to program database 'c:\Documents and Settings\matt\My Documents\Visual Studio Projects\notf\Debug\notf.pdb'; check for insufficient disk space, invalid path, or insufficient privilege .

Share this post


Link to post
Share on other sites
Assuming you haven't actually used up all the storage on your hard drive, usually rebooting your computer and then doing a rebuild all will fix that problem.

Share this post


Link to post
Share on other sites
The error indicates that the program is still running when you attempt to build it. Go into your Task Manager and kill the existing copy.

As for the code, it's wrong. You push one value back onto both v1 and v2, but you attempt to index the second value in v2 - which is empty.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
The error indicates that the program is still running when you attempt to build it. Go into your Task Manager and kill the existing copy.

As for the code, it's wrong. You push one value back onto both v1 and v2, but you attempt to index the second value in v2 - which is empty.


ok

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this