ifstream question, please assist!

This is a discussion on ifstream question, please assist! within the C++ Programming forums, part of the General Programming Boards category; hey fellas quick question.. i read the tutorial on opening files but i'm trying to open a file thats past ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    63

    ifstream question, please assist!

    hey fellas

    quick question.. i read the tutorial on opening files but i'm trying to open a file thats past to my function as a string.. i am trying this

    Code:
    ifstream in(fileName);
    where fileName is the string passed into my function and i get tons of IOSTREAM compiler errors.. along the lines of no matching type for ifstream::ifstream<string &> ...... tons of stuff here

    please assist!

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    have you included fstream.h

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    yes i have

    its included, the only thing i can think of is that i'm calling it from a constructor.. but that shouldn't matter cuz the constructor is sposta build my data structure off the content in this file!..

    i'm using multiple data files, i included this one in my second file, should i also include it in my main.cpp? i don't think that matters either.. lemme know!~
    SS3X

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    all the examples i see are of the format
    Code:
    ifstream in("FILENAME.TXT")
    this isn't similar cuz mine is a strict string.. not an arbitrary file.. right?? how do i implement for my scenario?

    thanks
    SS3X

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >along the lines of no matching type for ifstream::ifstream<string &>
    Is the variable you are passing to ifstream's constructor an object of the string class? If so then it won't work, the constructor takes a char * if I recall correctly, so you need to do something like this:

    ifstream in ( fileName.c_str() );

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    yes it is of the "string" class.. so i'll try your method when i get back to my linux coding box.. thanks for the reply and i hope it works..
    SS3X

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    63
    you da man.. works like a charm!
    SS3X

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 01:14 PM
  2. Simple ifstream Question
    By Paul22000 in forum C++ Programming
    Replies: 8
    Last Post: 12-05-2008, 05:34 PM
  3. question about ifstreams
    By Amyaayaa in forum C++ Programming
    Replies: 6
    Last Post: 05-27-2008, 04:48 PM
  4. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21