Solved

File handling in C++ on Linux/Unix platform

Posted on 2003-10-24
6
1,425 Views
Last Modified: 2010-07-27
Hi everyone,

I have a bunch of file handling code that I am writing in VC++ 6.0. I am mostly using the methods defined in <io.h> such as _finddata_t structure , _chdir(), rename(), _getcwd() and alike. At sime point it might be necessary to compile the application I am coding on a Linux platform. I don't think these methods are unix compatible. I don't have any experience coding on a linux/unix platform. I need to know if there are any file handling modules that can be compatible on both platforms or a way to make minimal changes to the existing code which makes it possible to compile it on a linux platform.

Any suggestions or reference to a resource(online, books,...) is appreciated.

onlyshiza
0
Comment
Question by:onlyshiza
6 Comments
 
LVL 6

Expert Comment

by:GaryFx
ID: 9615245
For the I/O itself, try sticking with the C++ library, specifically iostream and related classes.

Unfortunately, these don't address directory issues.  

Gary
0
 
LVL 2

Author Comment

by:onlyshiza
ID: 9615317
well,  it's mostly directory manipulation like finding the name of the current directory, file names in a directory or renaming/ deleting/ saving a file.
0
 
LVL 30

Accepted Solution

by:
Axter earned 80 total points
ID: 9615734
Most of the directory functions are available in Linux/UNIX.
However, you should remove the leading underscore when you use it in your code.

So use chdir() instead of _chdir().

chdir() will compile in Windows and Linux/UNIX, but _chdir() does not compile on Linux/UNIX.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:onlyshiza
ID: 9615749
thanks Axter. How about the _finddata_t structure. Is this also supported on Linux/UNIX or is there any similar structure?
0
 
LVL 30

Expert Comment

by:Axter
ID: 9615901
Unfortunately, the find directory logic is not the same.  Most Linux/UNIX platforms use the type of find directory functions used in the Bordland compiler.

You'll find other directory functions like chdir, mkdir, rmdir, etc..
0
 
LVL 4

Assisted Solution

by:dhyanesh
dhyanesh earned 40 total points
ID: 9616148
hi

info libc

Enter this at command prompt in linux for complete documentation of all available functions.

There are sub-topics for file handling and I/O.

Dhyanesh
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now