boost::filesystem::ifstream inputDataStream; //declaration of inputDataStream
Patrik this will not work the way you write it... First of all: According to C++ scope rules you create 2 streams: global and later in main a local one. this is not declaration!!! This is a global stream In your case you need to use a heap object (pointer) or pass the stream by reference to a function. With Kind Regards, Ovanes Markarian On Thu, August 10, 2006 15:08, pktao@uwm.edu wrote:
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 _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users