Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-10-2007, 04:14 AM
phantom3380's Avatar   
phantom3380 phantom3380 is offline
Newbie
 
Join Date: Apr 2007
Posts: 15
Rep Power: 7
phantom3380 is on a distinguished road
Unhappy Can someone tell me what is wrong with this vector?

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?
__________________
Yea as it was writ: "Compile and Run"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-10-2007, 07:00 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

You've to use the namespace, std.
You can use it by using, using namespace ___ or by using std and the scope operators.
Code:
#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 use
Code:
using namespace std;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-13-2007, 04:47 AM
phantom3380's Avatar   
phantom3380 phantom3380 is offline
Newbie
 
Join Date: Apr 2007
Posts: 15
Rep Power: 7
phantom3380 is on a distinguished road
Default

muchas gracias amigo
__________________
Yea as it was writ: "Compile and Run"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A challenge for anyone who wants one : ) digiology General Programming 1 03-03-2007 04:14 PM
Link buy goes wrong Kaabi Search Engine Optimization 5 01-08-2007 08:15 AM
What is wrong with this code convertion ? Jophry C and C++ 1 01-04-2007 01:10 PM
Whats wrong with my query!!! Saint Database & Database Programming 2 10-22-2006 07:09 PM
Something wrong... MrDiaz The Lounge 5 07-15-2006 01:57 PM


All times are GMT -5. The time now is 04:04 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads