Can you help with my issue with fstream in my little program here?

Discussion in 'C++' started by jjcp, Dec 28, 2006.

  1. jjcp

    jjcp Guest

    I would like to say thanks in advance for insight anyone can shed on
    this for me.

    Long story short from time to time I need to us C++ to take a list of
    file and make an index out of them in html. for this I use fstream both
    for input and output. So, i have a simple file that I just change few
    things on and I get the output formatted to what I want.

    So I installed FC6 on my home system and get out my handy usb drive
    because i needed my magic source file:

    #include <iostream>
    #include <fstream>
    #include <string>

    using namespace std;

    fstream fout("index.html", fstream::eek:ut );
    fstream fin("list.txt", fstream::in);


    int main()
    {
    string in;

    while(getline(fin, in))
    {
    fout << in << endl;
    }

    return 0;
    }


    to compile another html file for me. As you can see pretty cut and dry
    and to the point.

    My problem is compiling this file since I upgraded(?) to FC6 from FC5. I
    am using gcc version 4.1.1 20061011 (Red Hat 4.1.1-30) without any
    tweaks or changes from a std install.

    When I run:
    [charowl@localhost *****]$ gcc stuff.cpp

    I get:
    /tmp/ccxQXTd5.o: In function `__tcf_2':
    stuff.cpp:(.text+0xe): undefined reference to `std::basic_fstream<char,
    std::char_traits<char> >::~basic_fstream()'
    /tmp/ccxQXTd5.o: In function `__tcf_1':
    stuff.cpp:(.text+0x22): undefined reference to `std::basic_fstream<char,
    std::char_traits<char> >::~basic_fstream()'
    /tmp/ccxQXTd5.o: In function
    `__static_initialization_and_destruction_0(int, int)':
    stuff.cpp:(.text+0x53): undefined reference to `std::ios_base::Init::Init()'
    stuff.cpp:(.text+0x8b): undefined reference to `std::basic_fstream<char,
    std::char_traits<char> >::basic_fstream(char const*, std::_Ios_Openmode)'
    stuff.cpp:(.text+0xc3): undefined reference to `std::basic_fstream<char,
    std::char_traits<char> >::basic_fstream(char const*, std::_Ios_Openmode)'
    /tmp/ccxQXTd5.o: In function `__tcf_0':
    stuff.cpp:(.text+0x10c): undefined reference to
    `std::ios_base::Init::~Init()'
    /tmp/ccxQXTd5.o: In function `main':
    stuff.cpp:(.text+0x12b): undefined reference to `std::basic_string<char,
    std::char_traits<char>, std::allocator<char> >::basic_string()'
    stuff.cpp:(.text+0x140): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <char, std::char_traits<char>, std::allocator<char>
    >(std::basic_ostream<char, std::char_traits<char> >&,

    std::basic_string<char, std::char_traits<char>, std::allocator<char> >
    const&)'
    stuff.cpp:(.text+0x148): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
    std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char>
    >&)'

    stuff.cpp:(.text+0x150): undefined reference to
    `std::basic_ostream<char, std::char_traits<char>
    >::eek:perator<<(std::basic_ostream<char, std::char_traits<char> >&

    (*)(std::basic_ostream<char, std::char_traits<char> >&))'
    stuff.cpp:(.text+0x163): undefined reference to
    `std::basic_istream<char, std::char_traits<char> >& std::getline<char,
    std::char_traits<char>, std::allocator<char> >(std::basic_istream<char,
    std::char_traits<char> >&, std::basic_string<char,
    std::char_traits<char>, std::allocator<char> >&)'
    stuff.cpp:(.text+0x177): undefined reference to `std::basic_ios<char,
    std::char_traits<char> >::eek:perator void*() const'
    stuff.cpp:(.text+0x190): undefined reference to `std::basic_string<char,
    std::char_traits<char>, std::allocator<char> >::~basic_string()'
    stuff.cpp:(.text+0x1a6): undefined reference to `std::basic_string<char,
    std::char_traits<char>, std::allocator<char> >::~basic_string()'
    /tmp/ccxQXTd5.o:(.eh_frame+0x12): undefined reference to
    `__gxx_personality_v0'
    collect2: ld returned 1 exit status

    and nothing happens. Is my complier broken, my code?

    either way it would be nice to know. I have tried using every example
    of how to do this that google could find for me on fstream, and now I
    ask you. thanks -josh
     
    jjcp, Dec 28, 2006
    #1
    1. Advertising

  2. jjcp

    Jim Langston Guest

    "jjcp" <> wrote in message
    news:nXIkh.1471$...
    >I would like to say thanks in advance for insight anyone can shed on this
    >for me.
    >
    > Long story short from time to time I need to us C++ to take a list of
    > file and make an index out of them in html. for this I use fstream both
    > for input and output. So, i have a simple file that I just change few
    > things on and I get the output formatted to what I want.
    >
    > So I installed FC6 on my home system and get out my handy usb drive
    > because i needed my magic source file:
    >
    > #include <iostream>
    > #include <fstream>
    > #include <string>
    >
    > using namespace std;
    >
    > fstream fout("index.html", fstream::eek:ut );
    > fstream fin("list.txt", fstream::in);
    >
    >
    > int main()
    > {
    > string in;
    >
    > while(getline(fin, in))
    > {
    > fout << in << endl;
    > }
    >
    > return 0;
    > }
    >
    >
    > to compile another html file for me. As you can see pretty cut and dry
    > and to the point.
    >
    > My problem is compiling this file since I upgraded(?) to FC6 from FC5. I
    > am using gcc version 4.1.1 20061011 (Red Hat 4.1.1-30) without any tweaks
    > or changes from a std install.
    >
    > When I run:
    > [charowl@localhost *****]$ gcc stuff.cpp
    >
    > I get:
    > /tmp/ccxQXTd5.o: In function `__tcf_2':
    > stuff.cpp:(.text+0xe): undefined reference to `std::basic_fstream<char,
    > std::char_traits<char> >::~basic_fstream()'
    > /tmp/ccxQXTd5.o: In function `__tcf_1':
    > stuff.cpp:(.text+0x22): undefined reference to `std::basic_fstream<char,
    > std::char_traits<char> >::~basic_fstream()'


    <snip other errors along same line>

    I think it might be as simple as needing
    #include <ostream>
    #include <istream>

    at the top of your program. Include files are allowed to include other
    include files, or not as they see fit. Try this and see if it works.
     
    Jim Langston, Dec 28, 2006
    #2
    1. Advertising

  3. jjcp

    Guest

    Jim Langston wrote:
    > "jjcp" <> wrote in message
    > news:nXIkh.1471$...
    > >I would like to say thanks in advance for insight anyone can shed on this
    > >for me.
    > >
    > > Long story short from time to time I need to us C++ to take a list of
    > > file and make an index out of them in html. for this I use fstream both
    > > for input and output. So, i have a simple file that I just change few
    > > things on and I get the output formatted to what I want.
    > >
    > > So I installed FC6 on my home system and get out my handy usb drive
    > > because i needed my magic source file:
    > >
    > > #include <iostream>
    > > #include <fstream>
    > > #include <string>
    > >
    > > using namespace std;
    > >
    > > fstream fout("index.html", fstream::eek:ut );
    > > fstream fin("list.txt", fstream::in);
    > >
    > >
    > > int main()
    > > {
    > > string in;
    > >
    > > while(getline(fin, in))
    > > {
    > > fout << in << endl;
    > > }
    > >
    > > return 0;
    > > }
    > >
    > >
    > > to compile another html file for me. As you can see pretty cut and dry
    > > and to the point.
    > >
    > > My problem is compiling this file since I upgraded(?) to FC6 from FC5. I
    > > am using gcc version 4.1.1 20061011 (Red Hat 4.1.1-30) without any tweaks
    > > or changes from a std install.
    > >
    > > When I run:
    > > [charowl@localhost *****]$ gcc stuff.cpp
    > >
    > > I get:
    > > /tmp/ccxQXTd5.o: In function `__tcf_2':
    > > stuff.cpp:(.text+0xe): undefined reference to `std::basic_fstream<char,
    > > std::char_traits<char> >::~basic_fstream()'
    > > /tmp/ccxQXTd5.o: In function `__tcf_1':
    > > stuff.cpp:(.text+0x22): undefined reference to `std::basic_fstream<char,
    > > std::char_traits<char> >::~basic_fstream()'

    >
    > <snip other errors along same line>
    >
    > I think it might be as simple as needing
    > #include <ostream>
    > #include <istream>
    >
    > at the top of your program. Include files are allowed to include other
    > include files, or not as they see fit. Try this and see if it works.


    Why are you using gcc and not g++?

    Tolga Ceylan
     
    , Dec 28, 2006
    #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. Miguel Dias Moura
    Replies:
    2
    Views:
    371
    Martin
    Jun 22, 2004
  2. James Woody

    Yikes. A little help here.

    James Woody, Feb 4, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    394
    James Woody
    Feb 6, 2006
  3. Armando
    Replies:
    6
    Views:
    779
    Armando
    Jan 29, 2004
  4. Shawn
    Replies:
    8
    Views:
    407
    Shawn
    Sep 21, 2006
  5. mark4asp
    Replies:
    4
    Views:
    680
    TOUDIdel
    Dec 23, 2007
Loading...

Share This Page