LinuxQuestions.org
Visit Jeremy's Blog.
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
 
LinkBack Search this Thread
Old 03-10-2004, 08:49 PM   #1
Longinus
Member
 
Registered: Sep 2003
Distribution: Redhat 9.0 && Slackware 9.1
Posts: 420

Rep: Reputation: 30
Question how to save a file?


hi

ok so here is my plan:

make a program creates a .txt file in notepad

then its gonna insert some information into the newly created .txt file

and then its gonna save the file

my questions is how would i create and then save the file?

any suggestions?

thanks guys
 
Old 03-10-2004, 09:25 PM   #2
contrasutra
Guru
 
Registered: Mar 2003
Location: New Jersey
Distribution: Arch Linux
Posts: 1,445

Rep: Reputation: 46
Code:
`get your data via these commands` > file.txt
You can do "> foo.txt" to redirect STDOUT output to a text file. ">" overwrites any file that's there, ">>" appends onto the end.

Pretty simply shell scripting.
 
Old 03-10-2004, 09:45 PM   #3
Longinus
Member
 
Registered: Sep 2003
Distribution: Redhat 9.0 && Slackware 9.1
Posts: 420

Original Poster
Rep: Reputation: 30
hrm...

im having some troubles

#include <iostream>
#include <string>
using namespace std;

int main(){
string mystring = "Hello World";
mystring > helloworld.txt;

return 0;
}

and then it gives me this error:

exercise9.cc: In function `int main()':
exercise9.cc:7: `helloworld' undeclared (first use this function)
exercise9.cc:7: (Each undeclared identifier is reported only once for each
function it appears in.)

any suggestions?

thanks
 
Old 03-10-2004, 09:55 PM   #4
haobaba1
Member
 
Registered: Jul 2003
Location: VA Tech
Distribution: Mandrake 9.1
Posts: 73

Rep: Reputation: 15
Quote:
Originally posted by Longinus
hrm...

im having some troubles

#include <iostream>
#include <string>
using namespace std;

int main(){
string mystring = "Hello World";
mystring > helloworld.txt;

return 0;
}

and then it gives me this error:

exercise9.cc: In function `int main()':
exercise9.cc:7: `helloworld' undeclared (first use this function)
exercise9.cc:7: (Each undeclared identifier is reported only once for each
function it appears in.)

any suggestions?

thanks

You need to look at the fstream libraries. Specifically ofstream. Just create the file write out to it as you would cout and then close the file.
 
Old 03-10-2004, 10:08 PM   #5
contrasutra
Guru
 
Registered: Mar 2003
Location: New Jersey
Distribution: Arch Linux
Posts: 1,445

Rep: Reputation: 46
The example I gave was shell, NOT C. You use it in a BASH-type script or on the Command prompt.
 
Old 03-10-2004, 10:20 PM   #6
Longinus
Member
 
Registered: Sep 2003
Distribution: Redhat 9.0 && Slackware 9.1
Posts: 420

Original Poster
Rep: Reputation: 30
oh sorry my mistake :]
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to save file shadow11 Linux - Newbie 4 10-21-2004 08:15 PM
How to save the BIOS to file? iZvi General 0 10-16-2004 01:53 AM
where should I save this file??? bruno buys Linux - Software 2 08-17-2004 06:54 PM
Mozilla 1.7 - No File Save / File Open dialogs on Slackware 10.0 jayseye Slackware 8 08-10-2004 05:52 AM
php save file as ... ... Xiangbuilder Programming 1 11-25-2003 10:35 AM


All times are GMT -5. The time now is 03:31 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration