Results 1 to 3 of 3

Thread: Conversion Problem?

  1. #1

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    I am using this simple routine to copy a file.I use MFC(e1 is a variable for the EDIT control of type CString).I get a error because the compiler can not convert from string to CString.How to solve this?
    Code:
    #include <string>
    #include <fstream>
    #include <iostream>
    using namespace std;
    
    string got,all;;
    ifstream in("readme.txt");
    ofstream out("copy.txt");
    while(getline(in,got))
    	  out<<got<<"\n";
    all += got;
    e1 =all; 
    UpdateData(false);
    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
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Use:
    Code:
    e1 = all.c_str();
    The c_str() member function of the string class returns a const pointer to the character array. Basically, it's like saying:
    Code:
    char *pcStr = "Hello"
    CString x = pcStr;
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Thanks ,that's just what i was looking for.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width