2.2.5.4.2 stdioFile::ReadStringReadString
Description
Read a line from the current file position into a string and advance the file position. The end of line character is removed.
Syntax
BOOL ReadString( string & str, DWORD dwCntrl = 0 )
Parameters
- str
- [output]A reference to a string object that will contain the string when the function returns.
- dwCntrl
- [input] bits like FRS_EOL_CRLF_ONLY etc
Return
TRUE for success, FALSE for end of file reached, or other error.
Examples
EX1
//the following example will type out any ascii files from the User folder
void stdioFile_ReadString_ex1(string strfile = "origin.ini")
{
string strFilename = GetAppPath() + strfile;
stdioFile ff;
bool bRet = ff.Open(strFilename, file::modeRead);
if(!bRet)
{
out_str("file not found!");
return;
}
string strTemp;
while(ff.ReadString(strTemp))
out_str(strTemp);
ff.Close();
}
EX2
// this code read a sample ascii file and paste data to
// active worksheet line by line
void stdioFile_ReadString_ex2()
{
string strfile = "Samples\\Curve Fitting\\gamma.dat";
string strFilename = GetAppPath(true) + strfile;
stdioFile ff;
bool bRet = ff.Open(strFilename, file::modeRead);
if(!bRet)
{
out_str("file not found!");
return;
}
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
out_str("no active wks");
return;
}
string strTemp;
while(ff.ReadString(strTemp))
{
wks.PasteData(strTemp);
}
ff.Close();
}
Remark
Strings in ascii file might be separated by "\r\n", as typical of files fom DOS/Windows or can be just "\n" or just "\r", as typical of unix and MAC files. Both forms are supported by this function.
This function will also return TRUE on the last line even if it does not have a "\n" or "\r" termination. In other words, when reaching the end of a file, the function returns FALSE and the resulting string will always be empty.
Please note, so longer lines will be broken into multiple lines.
See Also
stdioFile::WriteString
Header to Include
origin.h
|