Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,158 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,104 people online right now. Registration is fast and FREE... Join Now!




how to create a text file

 
Reply to this topicStart new topic

how to create a text file, with c++ :)

Rating  5
thejasper
14 Dec, 2007 - 11:05 AM
Post #1

New D.I.C Head
*

Joined: 2 Nov, 2007
Posts: 28


My Contributions
Hello guys

I have a (little) question. I want to create a textfile automatically if it doesn't exist. Now my program writes to a txt file but you have to put the txt manually together with the exe. Who knows a solution

Thx smile.gif
User is offlineProfile CardPM
+Quote Post

Bench
RE: How To Create A Text File
14 Dec, 2007 - 11:17 AM
Post #2

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 617



Thanked: 14 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
That's a bit unclear, do you have an example of what you're trying to do, and the code you're using?
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: How To Create A Text File
14 Dec, 2007 - 11:19 AM
Post #3

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
http://www.cplusplus.com/doc/tutorial/files.html

User is offlineProfile CardPM
+Quote Post

no2pencil
RE: How To Create A Text File
14 Dec, 2007 - 11:58 AM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,444



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
Assuming you are using Linux you could always :

CODE

system("touch file");

User is online!Profile CardPM
+Quote Post

quim
RE: How To Create A Text File
14 Dec, 2007 - 08:02 PM
Post #5

D.I.C Head
Group Icon

Joined: 11 Dec, 2005
Posts: 145



Thanked: 2 times
Dream Kudos: 350
My Contributions
I know that in windows if you open a file, output file not input file, it will be created automatically.
check the like that Amadeus gave you.
CODE
ofstream fileout;
fileout.open("anyname.txt");

User is offlineProfile CardPM
+Quote Post

thejasper
RE: How To Create A Text File
15 Dec, 2007 - 01:57 AM
Post #6

New D.I.C Head
*

Joined: 2 Nov, 2007
Posts: 28


My Contributions
problem solved, thx quim and the others icon_up.gif
User is offlineProfile CardPM
+Quote Post

DPR
RE: How To Create A Text File
16 Dec, 2007 - 07:12 AM
Post #7

New D.I.C Head
*

Joined: 20 Dec, 2006
Posts: 17


My Contributions
In future, I suggest describing your problem with more detail, and possibly submitting an example of some of the code that you are using to try and achieve whatever it is you are trying to achieve
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 11:35PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month