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.

Recommended Answers

All 5 Replies

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]

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

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?

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

All the above. Not sure exactly what he wanted

Thank you guys. That's what I wanted. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.