error passing ifstream. why?

Discussion in 'C++' started by Giulio, Jun 24, 2003.

  1. Giulio

    Giulio Guest

    I've the following error in the sample code below.. I think it's caused from
    the passing of istream.
    what causes this problem?
    how can I solve it?

    thank you very much

    Giulio


    ---------------------------------------
    Compiler: Default compiler
    Building Makefile: "G:\Makefile.win"
    Executing make...
    make.exe -f "G:\Makefile.win" all
    g++.exe -c main.cpp -o
    ain.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/
    Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include"

    C:/Dev-Cpp/include/c++/bits/ios_base.h: In copy constructor
    `std::basic_ios<char, std::char_traits<char> >::basic_ios(const
    std::basic_ios<char, std::char_traits<char> >&)':
    C:/Dev-Cpp/include/c++/bits/ios_base.h:421: `std::ios_base::ios_base(const
    std::ios_base&)' is private
    main.cpp:12: within this context
    C:/Dev-Cpp/include/c++/streambuf: In copy constructor
    `std::basic_filebuf<char,
    std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char,
    std::char_traits<char> >&)':
    C:/Dev-Cpp/include/c++/streambuf:486: `std::basic_streambuf<_CharT,
    _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&)
    [with _CharT = char, _Traits = std::char_traits<char>]' is private
    main.cpp:12: within this context

    make.exe: *** [main.o] Error 1

    Execution terminated
    --------------------------------------

    the CODE
    ------------------------------------
    #include <fstream>
    #include <iostream>
    #include <stdlib.h>
    #include <string>
    using namespace std;
    int importFromCSV(ifstream is){
    return 5;
    }//end importFromCSV

    main (int argc, char *argv[]){
    ifstream is ("aaa");
    int q = importFromCSV(is);
    cout << q;
    system ("pause");
    return 0;
    }
    -----------------------------
     
    Giulio, Jun 24, 2003
    #1
    1. Advertising

  2. "Giulio" <giulio.gL E V > wrote...
    > I've the following error in the sample code below.. I think it's caused

    from
    > the passing of istream.
    > what causes this problem?


    std::ifstream doesn't have a usable copy c-tor.

    > how can I solve it?


    Never pass streams by value. Always use references.

    Victor
     
    Victor Bazarov, Jun 24, 2003
    #2
    1. Advertising

  3. Giulio

    Jon Bell Guest

    In article <EU2Ka.38798$>,
    Giulio <giulio.gL E V > wrote:
    >I've the following error in the sample code below.. I think it's caused from
    >the passing of istream.


    Yes. You can't pass istreams by value, because you can't copy them. Pass
    them by reference instead.

    >int importFromCSV(ifstream is){


    Change that to

    int importFromCSV(ifstream& is){

    --
    Jon Bell <> Presbyterian College
    Dept. of Physics and Computer Science Clinton, South Carolina USA
     
    Jon Bell, Jun 24, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Vinokur
    Replies:
    2
    Views:
    420
    Kevin Goodsell
    Aug 20, 2003
  2. csvka
    Replies:
    6
    Views:
    14,475
    John Harrison
    Feb 16, 2004
  3. Lingyun Yang
    Replies:
    2
    Views:
    906
    David Harmon
    Apr 11, 2004
  4. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    909
    Mark Rae
    Dec 21, 2006
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,995
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page