How to print the strings reading from file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ram Laxman

    How to print the strings reading from file

    Hi all,
    The below code doesnot print the string reading from the file?
    error C2679: binary '<<' : no operator defined which takes a
    right-hand operand of type 'class std::basic_stri ng<char,struct
    std::char_trait s<char>,class std::allocator< char> >' (or there is no
    acceptable conversion)
    Error executing cl.exe.

    Does anybody know how to fix it.Iam using VC++ 6.0.

    #include<fstrea m>
    #include<ios>
    #include <iostream.h>
    #include<string >
    #include<iomani p>
    #include<sstrea m>
    #include<vector >
    #include<algori thm>
    #include<stdio. h>
    #include <fcntl.h>
    #include <io.h>
    #include <cstdlib>
    #include <cstring>


    const char *filename ="C:\\result.tx t";
    //std::ostream &operator<<(std ::ostream &os, const mypair &p)

    using namespace std;

    int main()
    {

    string tok1;
    int result;
    string s1,s2("a");
    vector<int> v1;

    int status;
    status = _open(filename, _O_RDONLY);
    if(status == -1)
    {
    printf("Couldno t able to Open file ");
    }
    else
    {
    printf("Opening of file Successful");
    }

    ifstream ifs(filename); // Open for reading
    ofstream out("C:\divert. txt"); // Open for writing
    string s,line;
    while(getline(i fs, s)) // Discards newline char
    {

    // cout << s ; // ... must add it back
    s += line + "\n";
    // printf("%s",s);
    cout << s << endl;
    }
  • David Harmon

    #2
    Re: How to print the strings reading from file

    On 9 Feb 2004 23:22:04 -0800 in comp.lang.c++, ram_laxman@indi a.com (Ram
    Laxman) was alleged to have written:[color=blue]
    >Does anybody know how to fix it.Iam using VC++ 6.0.
    >
    >#include<fstre am>
    >#include<ios >
    >#include <iostream.h>[/color]

    Never use
    #include <iostream.h>
    It belongs to an old, obsolete, bad version of the io library that
    will make you crazy.

    Instead use
    #include <iostream>

    This will go along very happily with the
    using namespace std.
    that you already have.

    The same thing applies with less emphasis to the other .h C++ includes.

    Comment

    • John Harrison

      #3
      Re: How to print the strings reading from file


      "Ram Laxman" <ram_laxman@ind ia.com> wrote in message
      news:24812e22.0 402092322.361bd 090@posting.goo gle.com...[color=blue]
      > Hi all,
      > The below code doesnot print the string reading from the file?
      > error C2679: binary '<<' : no operator defined which takes a
      > right-hand operand of type 'class std::basic_stri ng<char,struct
      > std::char_trait s<char>,class std::allocator< char> >' (or there is no
      > acceptable conversion)
      > Error executing cl.exe.
      >
      > Does anybody know how to fix it.Iam using VC++ 6.0.
      >
      > #include<fstrea m>
      > #include<ios>
      > #include <iostream.h>[/color]

      Here's your error, <iostream>, no .h

      john


      Comment

      • Jonathan Turkanis

        #4
        Re: How to print the strings reading from file


        "David Harmon" <source@netcom. com> wrote in message
        news:40428ac6.4 5590726@news.we st.earthlink.ne t...[color=blue]
        > On 9 Feb 2004 23:22:04 -0800 in comp.lang.c++, ram_laxman@indi a.com[/color]
        (Ram[color=blue]
        > Laxman) was alleged to have written:[color=green]
        > >Does anybody know how to fix it.Iam using VC++ 6.0.
        > >
        > >#include<fstre am>
        > >#include<ios >
        > >#include <iostream.h>[/color]
        >
        > Never use
        > #include <iostream.h>
        > It belongs to an old, obsolete, bad version of the io library that
        > will make you crazy.[/color]

        Well, it was okay in its day. Some day there will be an 'oldies'
        revival. But if you have to use the old headers for some reason, you
        can't mix them with the new ones, such as <fstream>.
        [color=blue]
        >
        > Instead use
        > #include <iostream>
        >
        > This will go along very happily with the
        > using namespace std.
        > that you already have.
        >
        > The same thing applies with less emphasis to the other .h C++[/color]
        includes.[color=blue]
        >[/color]

        It's not quite the same. <iostream.h> and its cousins are prestandard
        headers which have been completely replaced by <iostream>, etc. The
        headers from the C standard librarary, ending in '.h', such as
        <stdio.h>, are part of the C++ standard library, and are perfectly
        okay to use. Unless you have some good reason, however, its better to
        use the versions prefixed by 'c', such as <cstdio>.

        Jonathan


        Comment

        • Frank Schmitt

          #5
          Re: How to print the strings reading from file

          ram_laxman@indi a.com (Ram Laxman) writes:
          [color=blue]
          > Hi all,
          > The below code doesnot print the string reading from the file?
          > error C2679: binary '<<' : no operator defined which takes a
          > right-hand operand of type 'class std::basic_stri ng<char,struct
          > std::char_trait s<char>,class std::allocator< char> >' (or there is no
          > acceptable conversion)
          > Error executing cl.exe.
          >
          > Does anybody know how to fix it.Iam using VC++ 6.0.
          >
          > #include<fstrea m>
          > #include<ios>
          > #include <iostream.h>
          > #include<string >
          > #include<iomani p>
          > #include<sstrea m>
          > #include<vector >
          > #include<algori thm>
          > #include<stdio. h>
          > #include <fcntl.h>
          > #include <io.h>
          > #include <cstdlib>
          > #include <cstring>[/color]

          - Don't use non-standard-includes (e.g. <iostream.h>)
          - Do you really need all of these?
          - You forgot to #include <string>

          HTH & kind regards
          frank

          --
          Frank Schmitt
          quattro research GmbH
          e-mail: schmitt NO at SPAM quattro-research !@! dot com

          Comment

          • David Harmon

            #6
            Re: How to print the strings reading from file

            On Tue, 10 Feb 2004 01:16:18 -0700 in comp.lang.c++, "Jonathan Turkanis"
            <technews@kanga roologic.com> was alleged to have written:[color=blue]
            >Well, it was okay in its day. Some day there will be an 'oldies'
            >revival. But if you have to use the old headers for some reason, you
            >can't mix them with the new ones, such as <fstream>.[/color]

            Or as in this case, <string>

            Comment

            Working...