Im having trouble calling an input file stream from inside a function and was
hoping if anyone can help me with a solution. Im compiling with MSVC++ 8.0.
Below is a detailed description of the problem:
The input file that Im trying to read is pt03-test-1.txt. Its just a text file
with 2 integer values in a single column:
24
35
the path to the file is : /tao/data/pt03-test-1.txt
The following code works:
#include <iostream>
#include <vector>
#include <fstream>
#include
#include
int main() {
boost::filesystem::ifstream inputDataStream("/tao/data/pt03-test-1.txt");
int mobilityIndexMarker = 0;
inputDataStream >> mobilityIndexMarker;
std::cout << mobilityIndexMarker << std::endl;
return (0);
};
Encapsulating the lines in main in a separate function breaks the code:
#include <iostream>
#include <vector>
#include <fstream>
#include
#include
boost::filesystem::ifstream inputDataStream; //declaration of inputDataStream
void trialOnsetWrite() {
int mobilityIndexMarker = 0;
inputDataStream >> mobilityIndexMarker;
std::cout << mobilityIndexMarker << std::endl;
};
int main() {
boost::filesystem::ifstream inputDataStream("/tao/data/pt03-test-1.txt");
trialOnsetWrite();
return (0);
};
Very Very Appreciative,
Patrick