C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 26th, 2005, 06:01 PM
triska13 triska13 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 2 triska13 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 41 sec
Reputation Power: 0
Reading files into vectors

Hi,

I've been trying to figure out how to do this for a while and I've never managed any luck with it.
I've got several assignments for a class that require it in various forms.
Basically I need to figure out how to read a txt file of words into a vector or array that stores strings.

I already have problems getting files read into a program in general, but the things I've tried to get
the strings (just words in most cases) into vectors hasn't worked yet.
If anyone could help me figure this out I'd greatly appreciate it.
If I need to provide more details just let me know.

Jyn

Reply With Quote
  #2  
Old March 27th, 2005, 10:48 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
You mean you need to create buffers for storing texts?
One of the appraoch is to overload ">>" operator, then suppose IfStream object is called as InArray , your ">>" operator would work like

InArray>>File.read() , where File is File object
[Similar to cin.getname() or cin>>Text]

HTH

Reply With Quote
  #3  
Old March 27th, 2005, 11:17 PM
triska13 triska13 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 2 triska13 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 41 sec
Reputation Power: 0
Essentially yah that's what I need, but I'm so bad with reading in files, I don't know how to code it.

I know I need an ifstream object and all that, I just don't know how to get it from the object into the vector.

The only example I have of reading in a file, goes character by character and I've got an idea of how to do it with that, I'm just hoping there's something simpler I can do. Is there a way to have the ifstream object read in a string rather than a character? without using getline probably cause I need it do words and not full lines, though I suppose if I have to I could break it down after reading, but I don't think it'd be very efficient cause the files I need to read in are up to a million words.

Reply With Quote
  #4  
Old March 30th, 2005, 08:34 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Best is to dynamically allocate memory and copy all file's content to it. This allocated memory can store many words. This is particularly easy in VC++ where there is concept of file mapping and globally allocating memory block.

For your case, there are methods that read line or string of text.
example cin.getline().

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Reading files into vectors


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT