S
s_amrollahi
Dear All
Hello
I am Saeed Amrollahi.
I encountered a very strange bug in my program. The problem is:
the program reads a formatted text file of trade summary in Tehran
Stock Exchange organization. In each line there are same fields like
Date (YYYYMMDD) Ticker Symbol Vol of Share Price ...
Based on date, I should check is there the file with the full path:
<Drive Letter>\StockExchangeDataCenter\TradeSummary\YYYY\MM\DD
if the file exists, I should append the line to the file and if there
isn't a file with above path, the program creates an empty file in
suitable path. An exception raised when
program want to create an empty file.
I am sure the path is correct, but I think Windows are sensible about
the depth of path. another part of program uses the following path:
<Drive Letter>\StockExchangeDataCenter\TradeSummary\YYYY
and it is OK!
I know my question may be an Off topic one, but please help me.
my code is here (the unrelated details were excluded):
void CAS400SysTrdSummaryInsDialog::InsRec(const string& s) // insert
string into data center's file
{
string ye;
ye = "2006";
string mo;
mo = "11";
string da;
da = "12";
// create correct path
map<string, string> m = g_DataCenterManager;
string PathName = DataCenterManager:ataCenterPath +
m["TRD_SUMMARY_CAT"] + m["AS400_DATA_SOURCE"] + ye + "mo + da +
".WIN";
CFileFind Finder;
BOOL b = Finder.FindFile(PathName.c_str());
if (!b) { // a file with <Year>.WIN should be created
AS400OutFile f(PathName); // <----- Exception raised!!!
try {
if (!f)
throw FileIsNotCreated();
}
catch(const FileIsNotCreated&) {
}
f.Close(); // closing file
/* ... */
}
else { // the file already have been created
AS400OutFile f(PathName, AS400OutFile::APPEND);
/* ... */
}
}
class AS400OutFile {
public:
enum OPEN_MODE { OUTPUT, APPEND };
AS400OutFile(std::string&, OPEN_MODE = OUTPUT); // use it for
creating and opening a file (for wrting into an AS/400 source file)
void Open(std::string&, OPEN_MODE = OUTPUT);
void Close();
~AS400OutFile();
// ...
private:
std::string PathName; // full pathname
std:fstream f; // stream file
};
inline AS400OutFile::AS400OutFile(std::string& PathName_, OPEN_MODE
m) :
PathName(PathName_)
{
if (m == OUTPUT)
f.open(PathName.c_str(), ios_base:ut); // open for write
else
f.open(PathName.c_str(), ios_base::app); // open for append
if (!f)
throw FileIsNotCreated(PathName);
}
As a final word, I learned from chapter 34 of C++ FAQ Lite:
Miscellaneous technical issues: "You should use forward slashes ("/")
rather than backslashes ("\") in your
#include filenames, even on an operating system that uses backslashes
such as DOS, Windows".
I use Visual C++ 6.0 under Windows XP.
Regards
Hello
I am Saeed Amrollahi.
I encountered a very strange bug in my program. The problem is:
the program reads a formatted text file of trade summary in Tehran
Stock Exchange organization. In each line there are same fields like
Date (YYYYMMDD) Ticker Symbol Vol of Share Price ...
Based on date, I should check is there the file with the full path:
<Drive Letter>\StockExchangeDataCenter\TradeSummary\YYYY\MM\DD
if the file exists, I should append the line to the file and if there
isn't a file with above path, the program creates an empty file in
suitable path. An exception raised when
program want to create an empty file.
I am sure the path is correct, but I think Windows are sensible about
the depth of path. another part of program uses the following path:
<Drive Letter>\StockExchangeDataCenter\TradeSummary\YYYY
and it is OK!
I know my question may be an Off topic one, but please help me.
my code is here (the unrelated details were excluded):
void CAS400SysTrdSummaryInsDialog::InsRec(const string& s) // insert
string into data center's file
{
string ye;
ye = "2006";
string mo;
mo = "11";
string da;
da = "12";
// create correct path
map<string, string> m = g_DataCenterManager;
string PathName = DataCenterManager:ataCenterPath +
m["TRD_SUMMARY_CAT"] + m["AS400_DATA_SOURCE"] + ye + "mo + da +
".WIN";
CFileFind Finder;
BOOL b = Finder.FindFile(PathName.c_str());
if (!b) { // a file with <Year>.WIN should be created
AS400OutFile f(PathName); // <----- Exception raised!!!
try {
if (!f)
throw FileIsNotCreated();
}
catch(const FileIsNotCreated&) {
}
f.Close(); // closing file
/* ... */
}
else { // the file already have been created
AS400OutFile f(PathName, AS400OutFile::APPEND);
/* ... */
}
}
class AS400OutFile {
public:
enum OPEN_MODE { OUTPUT, APPEND };
AS400OutFile(std::string&, OPEN_MODE = OUTPUT); // use it for
creating and opening a file (for wrting into an AS/400 source file)
void Open(std::string&, OPEN_MODE = OUTPUT);
void Close();
~AS400OutFile();
// ...
private:
std::string PathName; // full pathname
std:fstream f; // stream file
};
inline AS400OutFile::AS400OutFile(std::string& PathName_, OPEN_MODE
m) :
PathName(PathName_)
{
if (m == OUTPUT)
f.open(PathName.c_str(), ios_base:ut); // open for write
else
f.open(PathName.c_str(), ios_base::app); // open for append
if (!f)
throw FileIsNotCreated(PathName);
}
As a final word, I learned from chapter 34 of C++ FAQ Lite:
Miscellaneous technical issues: "You should use forward slashes ("/")
rather than backslashes ("\") in your
#include filenames, even on an operating system that uses backslashes
such as DOS, Windows".
I use Visual C++ 6.0 under Windows XP.
Regards