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.
roachic
0
Newbie Poster
Recommended Answers
Jump to PostOne 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
Jump to Postgetcwd() will return the full path to the current folder. Or ".\\myfile.txt" or "./myfile.txt"
All 5 Replies
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
roachic
0
Newbie Poster
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.