PDA

Click to See Complete Forum and Search --> : Conversion Problem?


Vlatko
Oct 4th, 2000, 01:50 PM
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?

#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

parksie
Oct 4th, 2000, 02:11 PM
Use:

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:

char *pcStr = "Hello"
CString x = pcStr;

Vlatko
Oct 4th, 2000, 02:38 PM
Thanks ,that's just what i was looking for.