0

I want to read a file which is in the same folder as my program. What is the notation to get the current folder? I tried '.' but it doesn't work.

3
Contributors
5
Replies
6
Views
9 Years
Discussion Span
Last Post by roachic
0

One way of getting the current folder is:

#include <direct.h>
#include <iostream>
int main()
{
   char buffer[100];
   getcwd(buffer, 100);
   std::cout << buffer << std::endl;
   return 0;
}

Niek

[edit] After trying the code I noticed that getcwd was declared deprecated, so you should use _getcwd instead
[/edit]

0

getcwd() will return the full path to the current folder. Or ".\\myfile.txt" or "./myfile.txt"

So... That's what he asked for right? Or did I read it wrong?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.