SumitKalsait
asked on
How to reading and writting string values from Formatted CFile ?
Hello I have to read or write string file in txt file like
Product name : Bla bla bla
Product ID : 12345
Product available : yes
Product purchase date: 12/3/09
if i like to change something like this
Product name : AA AA AA
How can i do it with CFile?
Thanks for the Help
Product name : Bla bla bla
Product ID : 12345
Product available : yes
Product purchase date: 12/3/09
if i like to change something like this
Product name : AA AA AA
How can i do it with CFile?
Thanks for the Help
For reading:
CStdioFile oFile;
if ( oFile.Open( strFileIndex, CFile::modeRead|CFile::sha reDenyWrit e ))
{
CString str;
if ( oFileIndex.ReadString( str ))
{
...
CStdioFile oFile;
if ( oFile.Open( strFileIndex, CFile::modeRead|CFile::sha
{
CString str;
if ( oFileIndex.ReadString( str ))
{
...
ASKER
but how to write at perticular position how to find the string that you want to edit, actually
str.Format( "Product ID : %d\n", 12345 );
oFile.WriteString( str );
replace whole content of the file with this written string thanks
str.Format( "Product ID : %d\n", 12345 );
oFile.WriteString( str );
replace whole content of the file with this written string thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try
{
CString str;
CStdioFile oFile( "test.txt", CFile::modeCreate|CFile::m
str.Format( "Product name : %s\n", "Bla Bla Bla" );
oFile.WriteString( str );
str.Format( "Product ID : %d\n", 12345 );
oFile.WriteString( str );
...
}
catch( CFileException )
{
}