CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

C++ noob topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 10-27-2007, 04:06 PM
Junior Member
 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
darkangel is on a distinguished road
| More
C++ noob

hallo,i am a university student and i am now staring to learn c++...i know quite a few things of java...
here is a part of my code

ifstream spammails[spam];
for(int i=0;i<spam;i++)
ifstream spammails[i](spamnames[i]);

(spam is an int,spamnames[] is a string array)

i receive the following error:
variable-sized object 'spammails' may not be initialized

what kind of initialialization do i have to make?give null values?
Reply With Quote
  #2  
Old 10-27-2007, 10:29 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,163
Thanks: 57
Thanked 63 Times in 44 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: C++ noob

You should be initializing the variables spammails with the input file streams.
Reply With Quote
  #3  
Old 10-28-2007, 03:14 AM
Junior Member
 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
darkangel is on a distinguished road
| More
Re: C++ noob

sorry,can you explain that a little bit?(i don't know much for the moment )
Reply With Quote
  #4  
Old 10-28-2007, 03:24 AM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,163
Thanks: 57
Thanked 63 Times in 44 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: C++ noob

Your variable type is ifstream and so you should be initializing it with the values it can contain and that is input file stream.
Reply With Quote
  #5  
Old 10-28-2007, 04:52 AM
Junior Member
 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
darkangel is on a distinguished road
| More
Re: C++ noob

well i am trying to initialize it with various input stream values
e.g

for(int i=0;i<spam;i++)
ifstream spammails[i]("something.txt");

(something.txt is a file in the same folder with the cpp file but i receive the same error) give me an example if you can....sorry and thanks in advance
Reply With Quote
  #6  
Old 10-28-2007, 08:47 AM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,163
Thanks: 57
Thanked 63 Times in 44 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: C++ noob

Thats not the way of initializing it. Try referring to the document where you should find a good sample for ifstream.
Reply With Quote
Reply

Thread Tools
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 Off
Pingbacks are Off
Refbacks are Off

 

Advertisement

CFanatic Search
Custom Search

Advertisement

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



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board