GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Oct-2003, 03:18
Katie Katie is offline
New Member
 
Join Date: Oct 2003
Posts: 1
Katie is an unknown quantity at this point

C++ Vectors


Hi,

Can anyone help me, I am in the middle of a project for college and I'm badly stuck. I'm trying to use Vectors in and also File I/O.
The problem occurs when I put in the import statements to alllow me to use vectors. When I put them in, the compiler no longer recognises my file stream object and comes up with the error:

C:\Program Files\Microsoft Visual Studio\MyProjects\Test\Test.cpp(23) : error C2872: 'ofstream' : ambiguous symbol
C:\Program Files\Microsoft Visual Studio\MyProjects\Test\Test.cpp(52) : error C2872: 'ifstream' : ambiguous symbol
Error executing cl.exe.

Test.exe - 2 error(s), 0 warning(s)

Ive tested the code for the files separately and the vector part separately and there's nothing wrong, both work perfectly, it seems to be just when I put em together. I'm ready to tear my hair out at this stage.
  #2  
Old 10-Oct-2003, 11:58
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
It might help if you post the code
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #3  
Old 11-Oct-2003, 09:11
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
I've seen that ifstream & ofstream are defined in both string and fstream.h. I guess you're using namespace std - but it doesn't seem to work sometimes. You've to be careful about which ifstream you're referring to. So for using ifstream/ofstream, I think you should try using the following syntax:

CPP / C++ / C Code:
std::ifstream file_h("myfile.txt");

Hope this works. Some compilers handle this better than others sadly.

GF
  #4  
Old 26-Oct-2003, 03:17
jmenendezr jmenendezr is offline
New Member
 
Join Date: Oct 2003
Posts: 3
jmenendezr is an unknown quantity at this point
The problem with Microsoft Visual C is that you have to include the files without the .h, it is

#include <iostream>
#include <fstream>

Hapened the same with me. Hope this help
  #5  
Old 26-Oct-2003, 03:20
jmenendezr jmenendezr is offline
New Member
 
Join Date: Oct 2003
Posts: 3
jmenendezr is an unknown quantity at this point
If you are using vectors and reading from a file, please i would like to take a look at your code, it would be of lot of help to me.

mail:jmenendezr@hotmail.com

Thx
  #6  
Old 17-May-2004, 23:36
Mjkramer21's Avatar
Mjkramer21 Mjkramer21 is offline
Awaiting Email Confirmation
 
Join Date: Mar 2004
Location: Orem, Ut
Posts: 36
Mjkramer21 is on a distinguished road

some vetor basics


Vectors are something like arrays accept you don't have to specify a size and elements can be automatically placed without specifying the element location. Vectors are used much like a push in a pop and push data structure of an array accept there is no popping off the back of the line. You do this by using the push_back function.

example:
CPP / C++ / C Code:
vector <int> theVector;

theVector.push_back(object);

some vector functions:

size()
empty()
max_size()
begin()
end()

But they are right, I can't be much more help without seeing your code.
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:36.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.