Its the string i've highlighted in red thats the problem...my compiler gives me the error message: "13 C:\Dev-Cpp\My Projects\vector.cpp
no matching function for call to `vector<int,allocator<int> >::at (int)'"
#include <iostream>
#include <stdlib.h>
#include <vector>
int main(int argc, char *argv[])
{
vector <int> vec(3,100);
cout << "Vector size is " << vec.size() << endl;
vec.push_back(7); vec.push_back(8); vec.push_back(9);
cout << "\t3 elements added" << endl;
cout << "Vector size is now " << vec.size() << endl;
cout << "\tFirst element is "<< vec.front() << endl;
cout << "\tSecond element is" << vec.at(1) << endl;
cout << "\tLast element is " << vec.back() << endl;
system("PAUSE");
return 0;
}
What gives? :confused: :confused: :confused: :confused:
Can someone tell me what is wrong with this vector?
Started by phantom3380, Apr 10 2007 12:14 AM
2 replies to this topic
#1
Posted 10 April 2007 - 12:14 AM
Yea as it was writ: "Compile and Run" :p
|
|
|
#2
Posted 10 April 2007 - 03:00 AM
You've to use the namespace, std.
You can use it by using, using namespace ___ or by using std and the scope operators.
You can use it by using, using namespace ___ or by using std and the scope operators.
#include <iostream>
#include <vector>
int main()
{
std::vector<int> vec(3, 100);
std::cout << "Vector size is " << vec.size() << std::endl;
vec.push_back(7);
vec.push_back(8);
vec.push_back(9);
std::cout << "\t3 elements added" << std::endl;
std::cout << "Vector size is now " << vec.size() << std::endl;
std::cout << "\tFirst element is " << vec.front() << std::endl;
std::cout << "\tSecond element is " << vec.at(1) << std::endl;
std::cout << "\tLast element is " << vec.back() << std::endl;
system("PAUSE");
return 0;
}
In that example, I'm using the scope operators, but you can also just useusing namespace std;
#3
Posted 13 April 2007 - 12:47 AM


Sign In
Create Account


Back to top









