开发者

C++ file output

All,

I am not a programming idiot, but the following code produces 0 byte file开发者_开发问答s. I verified the filename is correct, and the files are created. I even went so far as to make the files read, write, and execute for everyone, and specify the files be truncated and not just recreated everytime, and still 0 byte files.

fstream fs;
fs.clear();
fs.open(dataFileName.c_str(), fstream::out| fstream::trunc);
std::cout << dataFileName.c_str() << std::endl;

for (int idx = 0; idx < theNumberHorizontalPoints; ++idx)
{
   for (int zdx = 0; zdx < theVerticalProfilePtr->getNumberVerticalLevels(); ++zdx)
   {
      fs << theThermalArray[idx][zdx] << " ";
   }
   fs << std::endl;
   fs.flush();
}
fs.close();


Important parts of the code are missing. What are the dimensions of your array?

The rest of the code seems to be good, so I wrote a small test application that writes numbers [1-6] to a file named demo.txt.

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    fstream fs;
    fs.clear();
    fs.open("demo.txt", fstream::out | fstream::trunc);

    int theThermalArray[][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
    int theNumberHorizontalPoints = 2;

    for (int idx = 0; idx < theNumberHorizontalPoints; ++idx)
    {
       for (int zdx = 0; zdx < 3; ++zdx)
       {
          fs << theThermalArray[idx][zdx] << " ";
       }
       fs << std::endl;
       fs.flush();
    }
    fs.close();
}


If theNumberHorizontalPoints is zero or less you will give the result you describe.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜