LinuxQuestions.org
Review your favorite Linux distribution.
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 05-08-2006, 04:29 AM   #1
necrolin
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Rep: Reputation: 0
Question Creat files C++


I'm learning C++ and have encountered a problem. I want my program to be able to create new files and directories. Using fstream I can only open & write to files that already exist, which doesn't happen to be that useful.

So in point form:
Problem: How do I create new files/directories using C++
Preferably: System independant solution, something that will work in both Linux and Windows without any changes (if possible).

Thanks
 
Old 05-08-2006, 05:49 AM   #2
Artanicus
Member
 
Registered: Jan 2005
Location: Finland
Distribution: Ubuntu, Debian, Gentoo, Slackware
Posts: 827

Rep: Reputation: 31
well, about creating files, you're wrong..
Code:
// example to demonstrate it
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
   ofstream out("filethatdoesntexist.txt");
   out << "howdy" << endl;
   return 0;
}
Creating directories is a bit more complex, id say you better check out:
Code:
man 2 mkdir
There is no OS independant way to do it.. /:
 
Old 05-08-2006, 06:01 AM   #3
necrolin
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Original Poster
Rep: Reputation: 0
Talking Thanks

Thanks Artanicus, that did the trick. I can see where I was making a mistake in my code now.
 
Old 05-08-2006, 06:33 AM   #4
nhydra
Member
 
Registered: May 2006
Distribution: Fedora Core, FreeSpire, PC-BSD, NetBSD
Posts: 96

Rep: Reputation: 15
For creating the dirs and all manipulating action just use GNU C Library.

Here is a link about the file system interface in *unix like OSes that use GCC:

http://www.gnu.org/software/libc/man...em%20Interface
 
Old 05-09-2006, 07:06 PM   #5
necrolin
LQ Newbie
 
Registered: Jun 2003
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks nhydra, that's a really useful site for me.
 
  


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
creat boot disk ust Linux - General 1 10-07-2005 08:34 PM
unable to creat io-slave Penguin of Wonder Linux - Hardware 0 09-26-2005 01:29 AM
how to creat /dev/loop8 abd_bela Debian 1 12-15-2004 03:45 PM
hello i want to know how to creat tar Paxmaster Linux - General 1 10-29-2004 05:03 PM
how to Creat a User cerberus Slackware 4 05-14-2003 10:00 PM

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

All times are GMT -5. The time now is 03:54 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