Boost logo

Boost Users :

From: pktao_at_[hidden]
Date: 2006-08-10 09:08:30


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 <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>

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 <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>

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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net