#include <iostream>
#include <fstream>
#include <string>
#include <vector>
std::ifstream iFile;
std::string string;
std::vector<std::streampos> titlePos;
int main()
{
iFile.open("presets.txt", std::ios_base::app);
if (!iFile.is_open())
{
std::cout << "iFile presets isnt open" << std::endl;
}
while (!iFile.eof())
{
iFile >> string;
if (string == "%title")
{
iFile >> string;
titlePos.emplace_back(iFile.tellg());
}
}
for (int x = titlePos.size() - 1; x != -1; --x)
{
iFile.seekg(titlePos[x]);
std::cout << titlePos[x] << std::endl;
std::cout << iFile.tellg() << std::endl;
}
return 0;
}
For some reason, the cout
for listPos[x]
are all usual (I think), but once I transfer the streampos
values to the ifstream iFile
, they all result in a -1 being outputted (an error, I assume).
I do not understand why transferring the values causes an error, or how I would go about finding the cause of the error.
IN "presets.txt"
%title loc1
%title loc2
%title loc3
OUTPUT
-1
-1
26
-1
11
-1