LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2006, 03:37 PM   #1
kev000
Member
 
Registered: Oct 2006
Posts: 53

Rep: Reputation: 15
C++ directory "where am I" function


Could anyone direct me on how my Linux program could know what directory it is in?

I need to write a function to return that info in c/c++. Any ideas on how I could do that?

my idea is:

char* whereami()
{
return Directory_Where_Im_At;
}

Last edited by kev000; 11-17-2006 at 03:38 PM.
 
Old 11-17-2006, 03:51 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Code:
#include <unistd.h>
#include <iostream>

int main(int argc, char **argv)
{
    using namespace std;
    cout << "current working directory is " << get_current_dir_name() << endl;
    return 0;
}
The get_current_dir_name function isn't portable to non-GNU implementations of the standard C libraries. Check out the manual page for getcwd for alternatives.
 
Old 11-17-2006, 04:18 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
man getcwd
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"substraction" and "division" function in OpenOffice Calc mac1234mac Linux - Software 7 12-03-2009 06:36 AM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM
When "function pointer" meets "template"... I can't get rid of this compiling er cyu021 Linux - Software 3 12-17-2004 07:52 PM
"Function not implemented" error in call to "sem_open()" Krishnendu8 Linux - Newbie 1 06-07-2003 02:52 AM
"Function not imlemented" error in call to "sem_open()" Krishnendu8 Linux - Networking 0 06-07-2003 02:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration