C++/C++

Advertisement


Question
I am a newbie using C++ and I am presently working on with files. I know how to read files which are in the current working directory. In my program I will be reading files from different directories and hence I need to specify the file path each time I am accesing that file. I need a sample code which will help me to read .csv files which are tokenized using strtok() function. Can yop please let me know how to specify the paths for the files that I am reading.

Thanks,
Rishi

Answer
You can give the file name (including path) as input to fstream constructor or fstream open method, or stdio open method or whichever file opening method you are using. On windows, you can give, for example,

fstream f;
f.open("C:\\example.csv"); // two back slashes, one to escape the next backslash

Hope that helps.  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Amit Kumar

Expertise

I can answer Cplusplus language and library questions, including STL, ACE, Boost. I have a good background in Mathematics.

Experience

Programming in CPP for about 8 years. Industry experience of 4 years.

Education/Credentials
Bachelors and Masters in Computer Science from Indian Institute of Technology Delhi.

©2016 About.com. All rights reserved.