Original Post
Some code of mine doesn't seem to be working (it compiles and runs, but doesn't output the right thing). I recreated the problem with the following code (I stripped out all the irrelevant code). The file, h.txt, contains a huge array of 0s and 1s (768 lines with 1024 1s and 0s). I read them into an array (a vector of vectors). Then I try writing them back out into the file, whattheheck.txt, in the same format. Every time I run this, I get all 0s, even if the input file had a large number of 1s. What could be causing this? Should I try something besides a vector of vectors? Am I reading it in wrong? FYI, I'm running it on a SGI Octane2 running IRIX. Thanks. Edit: If it's not already obvious, this is C++.
#include <fstream>
#include <vector>
int main()
{
std::vector < std::vector < bool > > h;
std::ifstream in;
std::ofstream out;
int temp;
for (int x = 0; x < 1024; x++)
{
h.push_back(std::vector < bool > ());
for (int y = 0; y < 768; y++)
{
h[x].push_back(false);
}
}
in.open("h.txt");
for (int y = 0; y < 768; y++)
{
for (int x = 0; x < 1024; x++)
{
in >> temp;
if (temp == 1)
{
h[x][y] = true;
}
else
{
h[x][y] = false;
}
}
}
in.close();
out.open("whattheheck.txt");
for (int y = 0; y < 768; y++)
{
for (int x = 0; x < 1024; x++)
{
if (h[x][y] == true)
{
out << "1";
}
else
{
out << "0";
}
if (x < 1024 - 1)
{
out << " ";
}
}
out << std::endl;
}
out.close();
return 0;
}