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 09-15-2010, 12:39 PM   #1
Tacitus
LQ Newbie
 
Registered: Sep 2010
Posts: 2

Rep: Reputation: 0
Lightbulb Trying to read entire text files into c++


Hi, im making a program (for the heck of it) that rewrites it code everytime it is run.(my ambition is to turn it into my c++ teacher and watch her be confuzled as to why she cant read my code and why it does weird things)

Ive just started c++ programming, and managed to rewrite a program so that when it is run a second time, it says hello world. My problem is that I can only input the file as a single string. What I need to do is to be able to input the entire file into the c++ program, as a single object and then ifstream it out with the destination as the source code.

Also, it would help alot if there was someway to write additional lines to an existing text file instead of overwriting what is already there. That way, every time my c++ runs and rebuilds itself, it adds another couple of lines of code to a txt file and when the final iteration is complete, it loads a text file that was created by the program and uses it to program itself. I heard there is some sort of spawn command, can it be used to open up notepad and write to it? it would be awsome if my various programs could open different notepads with various messages.

(as a side note if I can get it to do that, ill use the rand function to load random pieces and parts that fit together and work together as a whole, but do different things.)
ty so much!
 
Old 09-15-2010, 03:18 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Are you actually trying to write a mutating virus?
 
Old 09-15-2010, 03:56 PM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Tacitus View Post
my ambition is to turn it into my c++ teacher and watch her be confuzled as to why she cant read my code and why it does weird things
I have known very few teachers for whom such a stunt would be a good idea.

Quote:
My problem is that I can only input the file as a single string. What I need to do is to be able to input the entire file into the c++ program, as a single object
Is there a typo in there? I really don't get the distinction between what you already figured out how to do vs. what you need help with.

Quote:
Also, it would help alot if there was someway to write additional lines to an existing text file instead of overwriting what is already there.
That is pretty trivial.

Do you really need to be working on a lame stunt in order to motivate yourself to learn C++?

Your questions are mostly about basic I/O operations and system requests that should be very easy to learn if you put a little effort into learning them first.

Later, if you're still interested in programming lame stunts, you'll know how.
 
  


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
how can i get my scripts to read/write text from/to specific parts of files? Siljrath Linux - General 12 02-06-2010 02:58 PM
[SOLVED] Read large text files (~10GB), parse for columns, output vache Programming 57 04-07-2009 10:51 PM
Read text files alanlow Programming 1 04-15-2004 10:07 AM
C: Best way to read an entire text file and putting it in a *char. Claus Programming 8 03-15-2004 01:22 PM
need a perlscript to read from a text file and transfer files via ftp cccc Linux - Networking 2 02-21-2004 06:18 PM

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

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