How to print the strings reading from file

Discussion in 'C++' started by Ram Laxman, Feb 10, 2004.

  1. Ram Laxman

    Ram Laxman Guest

    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_string<char,struct
    std::char_traits<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<fstream>
    #include<ios>
    #include <iostream.h>
    #include<string>
    #include<iomanip>
    #include<sstream>
    #include<vector>
    #include<algorithm>
    #include<stdio.h>
    #include <fcntl.h>
    #include <io.h>
    #include <cstdlib>
    #include <cstring>


    const char *filename ="C:\\result.txt";
    //std::eek:stream &operator<<(std::eek:stream &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("Couldnot 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(ifs, s)) // Discards newline char
    {

    // cout << s ; // ... must add it back
    s += line + "\n";
    // printf("%s",s);
    cout << s << endl;
    }
    Ram Laxman, Feb 10, 2004
    #1
    1. Advertising

  2. Ram Laxman

    David Harmon Guest

    On 9 Feb 2004 23:22:04 -0800 in comp.lang.c++, (Ram
    Laxman) was alleged to have written:
    >Does anybody know how to fix it.Iam using VC++ 6.0.
    >
    >#include<fstream>
    >#include<ios>
    >#include <iostream.h>


    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.
    David Harmon, Feb 10, 2004
    #2
    1. Advertising

  3. "Ram Laxman" <> wrote in message
    news:...
    > 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_string<char,struct
    > std::char_traits<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<fstream>
    > #include<ios>
    > #include <iostream.h>


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

    john
    John Harrison, Feb 10, 2004
    #3
  4. "David Harmon" <> wrote in message
    news:...
    > On 9 Feb 2004 23:22:04 -0800 in comp.lang.c++,

    (Ram
    > Laxman) was alleged to have written:
    > >Does anybody know how to fix it.Iam using VC++ 6.0.
    > >
    > >#include<fstream>
    > >#include<ios>
    > >#include <iostream.h>

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


    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>.

    >
    > 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.
    >


    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
    Jonathan Turkanis, Feb 10, 2004
    #4
  5. (Ram Laxman) writes:

    > 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_string<char,struct
    > std::char_traits<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<fstream>
    > #include<ios>
    > #include <iostream.h>
    > #include<string>
    > #include<iomanip>
    > #include<sstream>
    > #include<vector>
    > #include<algorithm>
    > #include<stdio.h>
    > #include <fcntl.h>
    > #include <io.h>
    > #include <cstdlib>
    > #include <cstring>


    - 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
    Frank Schmitt, Feb 10, 2004
    #5
  6. Ram Laxman

    David Harmon Guest

    On Tue, 10 Feb 2004 01:16:18 -0700 in comp.lang.c++, "Jonathan Turkanis"
    <> was alleged to have written:
    >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>.


    Or as in this case, <string>
    David Harmon, Feb 10, 2004
    #6
    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. Bryan Shaw

    Lock Print Screen and File Print

    Bryan Shaw, Apr 19, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,931
    Kevin Spencer
    Apr 20, 2005
  2. Arun Kumar Srinivasan

    Using javax.print classes to print text/file

    Arun Kumar Srinivasan, Jan 13, 2004, in forum: Java
    Replies:
    5
    Views:
    6,114
    Gregory A. Swarthout
    Jan 14, 2004
  3. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    730
    Malcolm
    Jun 24, 2006
  4. keto
    Replies:
    0
    Views:
    896
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    334
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page