谁能告诉我这有什么问题?
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
class writeManager
{
std::vector<double> valueVector;
std::ofstream ofsFile;
public:
writeManager(void);
void writeOnFile(int);
void openOfsStreams(void);
void closeOfsStreams(void);
};
writeManager::writeManager(void)
{
openOfsStreams();
ofsFile << "FIRST LINE" << std::endl;
closeOfsStreams();
}
void writeManager::writeOnFile(int input)
{
openOfsStreams();
if(ofsFile.good())
{
ofsFile << input << std::endl;
}
else
{
std::cout << "Hey!" << std::endl;
}
ofsFile.close();
}
void writeManager::openOfsStreams(void)
{
ofsFile.open("/home/user/example.txt");
}
void writeManager::closeOfsStreams(void)
{
ofsFile.close();
}
int main()
{
writeManager writeObject;
for (unsigned int i = 0; i!= 5; i++)
{
writeObject.writeOnFile(i);
}
}
我想在文件“example.txt”上看到这个输出
FIRST LINE
0
1
2
3
4
但我只得到
4
PS:没有“嘿!” 被打印。