Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Failure in file creation and exception raised (http://www.velocityreviews.com/forums/t501627-failure-in-file-creation-and-exception-raised.html)

s_amrollahi@yahoo.com 04-15-2007 08:22 PM

Failure in file creation and exception raised
 
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::DataCenterPath +
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::ofstream f; // stream file
};

inline AS400OutFile::AS400OutFile(std::string& PathName_, OPEN_MODE
m) :
PathName(PathName_)
{
if (m == OUTPUT)
f.open(PathName.c_str(), ios_base::out); // 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


Howard 04-16-2007 04:10 PM

Re: Failure in file creation and exception raised
 

<s_amrollahi@yahoo.com> wrote in message
news:1176668533.473916.315800@y80g2000hsf.googlegr oups.com...
> 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):
>


Perhaps the directory does not exist? You can't create a file in a
directory unless the directory has been created first. (And for information
on creating directories, you need to ask on a Windows newsgroup.)

-Howard



All times are GMT. The time now is 09:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.