#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    7
    Rep Power
    0

    Problem with accessing data in std::vector


    Hi.

    I have arrays of characters stored inside a vector. The strings are files I'd like to open and read.

    This is my code

    Code:
    for(int i = 0; i < filevec.size(); i++) {	
    	ifstream infile (filevec[i]);
    	//read in values
    }
    And I get an error that says

    Code:
    No user-defined-conversion operator available
    that can perform this conversion, 
    or the operator cannot be called
    Is there away around this?
    Thanks.
  2. #2
  3. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    12
    Can you show us a bit more of your code? In particular the definition of your vector would be useful.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    7
    Rep Power
    0
    Here's how I defined my vector
    Code:
    vector <string> filevec;						//vector containing filenames
    I tried using ".c_str" but it won't open the file much less write into it

    Code:
    for(int i = 0; i < filevec.size(); i++) {	
    	ifstream filein (filevec[i].c_str(), ios::in);
    	assert (filein);
    	//read in values
    }
    How should I get this done? Thanks in advance
    Last edited by C++ Padua; July 13th, 2003 at 11:20 PM.
  6. #4
  7. Left due to despotic ad-min
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Posts
    1,044
    Rep Power
    14
    The problem is with your assert statement; std::stream and derived types (eg std::ifstream) do not provide an operator int() member.

    If you want to test the stream to see if opening succeeded use

    assert(!(!filein));

    This will terminate your program if the file can't be opened for reading --- a bit draconian IMHO, but that's apparently what you want ....

IMN logo majestic logo threadwatch logo seochat tools logo