Hello
I want to read line from txt file when i pressed the button
please any one have code using MFC.
Printable View
Hello
I want to read line from txt file when i pressed the button
please any one have code using MFC.
Read up on CStdioFile
CStdioFile inFile;
CFileException efile;
CString strFirstLine;
inFile.Open("test.txt",CFile::modeRead|CFile::typeText);
inFile.ReadString(strFirstLine);
m_List1.AddString(inFile);
am doing this , but giving me error
When i Used fstream..
CString str,Str1;
int a;
UpdateData();
str= m_EditBox;
fout.open("abc.txt");
fout<< "Name";
fout.close();
ifstream in;
in.open("abc.txt");
while(!in.eof())
{
in >> Str1; /// Error Comes here no operator ">>" matches these operands
}
UpdateData(FALSE);
m__myListBox.AddString(Str1);
use ifstream with char or char string.
And from next post use CODE tag.Code:char readStr[512];
ifstream myFile("fileName");
while (!myFile.eof())
{
myFile >> readStr;
}
myFile.close();
Thanks for the Help.
I did this but this time nothing is getting in the ReadStr variable :(
It perfectly does. Check the loop, it read and store each strings from file, then again reads next string. For storing all string in a single buffer you need to add each readStr in a buffer. ie:
Check the file name and path for be sure that you are reading correct file.Code:while (!myFile.eof())
{
myFile >> readStr;
szBuf += readStr; //CString szBuf
}
// now you have all the txt from file in CString szBuf here.
And for using fstream did you put using namespace std; at the top. ?
Yup i did..its working :)
in this program i given the string.
Now i am trying to do to take string from the Edit Box but its not Writing in the file puts ASCI and radam numbers
1. Please, use Code tags around code snippets.
2. To help us to help you you should always explain what exact error you had and, if possible, show the exact error message.
3. What is m_List1? Is it a CListBox instance? If *yes* then what can it have to do with a CStdioFile object passed in as a parameter? :confused:
You, perhaps, wanted to pass in the CString strFirstLine object containing the text you had read from a file?
VictorN thanks for your reply. this prob is solved
now i want to write data from the Edit Box.. its writing random numbers not the string
@code:
ofstream Students("test.txt", ios::out);
CString name;
name=m_editbox;
Students << name ;
Students.close();
I think you need some books and study about windows programming (as well as basic c++) then try to develop some application, rather than asking each steps in forum.
I dont know eactly how to tag code...SOrry :(
hypheni : Yup i am new to MFC Windows programming. i asked for the related to this ..but no body tell me, so thats why am facing problem in syntax mostly
As you were already told in your another thread: