1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ noob

Discussion in 'C++' started by imported_darkangel, Oct 27, 2007.

  1. imported_darkangel

    imported_darkangel New Member

    Joined:
    Oct 27, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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(spamnames);

    (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?
    :confused:
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
    You should be initializing the variables spammails with the input file streams.
     
  3. imported_darkangel

    imported_darkangel New Member

    Joined:
    Oct 27, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    sorry,can you explain that a little bit?(i don't know much for the moment:( )
     
  4. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
    Your variable type is ifstream and so you should be initializing it with the values it can contain and that is input file stream.
     
  5. imported_darkangel

    imported_darkangel New Member

    Joined:
    Oct 27, 2007
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    well i am trying to initialize it with various input stream values
    e.g

    for(int i=0;i<spam;i++)
    ifstream spammails("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
     
  6. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
    Thats not the way of initializing it. Try referring to the document where you should find a good sample for ifstream.
     

Share This Page