473,385 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Text Files

compman9902
105 100+
I know that this subject is a little drawn out, but I do need some help.
I have searched google for a while but still can't seem to get an answer.
All I need is the code for a few things (links to tutorials will do fine as well).
1.) Creating a text file at a user-defined location and then filling it with a few lines of pre-assigned numbers
2.)Reading a text file at a user-defined location and then creating a second text file using the original file name at the same location (ex. Reads ex.txt and makes Eex.txt)
That is all I need. Here is what I'm working with:
Expand|Select|Wrap|Line Numbers
  1. string locationOne;
  2. string locationTwo;
  3. string nameOne;
  4. string nameTwo;
  5. string filler;
  6. cout << "Please Enter The Location Of The File You Want To Write To: " << endl;
  7. cin   >> locationOne;
  8. cout << "Please Enter The Location Of The File You Want To Read: " << endl;
  9. cin  >> locationTwo;
  10. cout << Please Enter The Name Of The File You Want To Write To: << endl;
  11. cin  >> nameOne;
  12. nameTwo = "E" + nameOne;
  13.  
locationOne = The File To Write To
locationTwo = The File To Read
nameOne = The Name Of The File To Write To
name Two = The Name Of The Modified File To Write To
filler = What I put in the text files
Please either give me an example using the above variables or give me a link to a helpful tutorial
Thank You
Mar 21 '07 #1
5 1357
horace1
1,510 Expert 1GB
have a look at
http://www.cplusplus.com/doc/tutorial/files.html
Mar 21 '07 #2
compman9902
105 100+
have a look at
http://www.cplusplus.com/doc/tutorial/files.html
I have and I have to tell you..I don't really understand it.
Every time I try to do this:
Expand|Select|Wrap|Line Numbers
  1. ofstream myfile;
  2. myfile.open (locationOne);
  3. myfile << "Writing this to a file.\n";
  4. myfile.close();
  5.  return 0;
I get an error on the "myfile.open (locationOne);" part.
Mar 21 '07 #3
Ganon11
3,652 Expert 2GB
This is because your compiler expects a character array (cstring) in the open() command rather than a string. Instead of
Expand|Select|Wrap|Line Numbers
  1. myInputStream.open(myString);
write

Expand|Select|Wrap|Line Numbers
  1. myInputStream.open(myString.c_str());
and the error should be fixed.
Mar 21 '07 #4
compman9902
105 100+
This is because your compiler expects a character array (cstring) in the open() command rather than a string. Instead of
Expand|Select|Wrap|Line Numbers
  1. myInputStream.open(myString);
write

Expand|Select|Wrap|Line Numbers
  1. myInputStream.open(myString.c_str());
and the error should be fixed.
That only answers a few of my questions. Also, please tell me how to open the file save and file open dialogs
Thanks
Mar 22 '07 #5
Roonie
99
you can use myInputStream.getline() to read in lines from your file. you can then feed them into a new file that you create in much the same way as the first.
Mar 22 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

27
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there...
0
by: Steve | last post by:
My application uses transfertext to create text files that are FTPed to a website and are processed by a webstore. The text files can be for one of three purposes: Add one or more items to the...
16
by: thenightfly | last post by:
Ok, I know all about how binary numbers translate into text characters. My question is what exactly IS a text character? Is it a bitmap?
0
by: richardkreidl | last post by:
I have the following hash script that I use to compare two text files. 'Class Public Class FileComparison Public Class FileComparisonException Public Enum ExceptionType U 'Unknown A 'Add...
3
by: Frustrated Developer via DotNetMonster.com | last post by:
I have posted a couple times on here already and found the user community to be very helpful. I took on a project before I realized how difficult a time I'm having working with a database....
10
by: joelagnel | last post by:
hi friends, i've been having this confusion for about a year, i want to know the exact difference between text and binary files. using the fwrite function in c, i wrote 2 bytes of integers in...
5
by: praveenholal | last post by:
Hi Freinds , I want to convert the files that are in text format (.txt) to CSV file. I am working on Linux. So can anyone guide me. Here is my problem Description I have some result files...
29
by: list | last post by:
Hi folks, I am new to Googlegroups. I asked my questions at other forums, since now. I have an important question: I have to check files if they are binary(.bmp, .avi, .jpg) or text(.txt,...
1
by: Xah Lee | last post by:
Text Processing with Emacs Lisp Xah Lee, 2007-10-29 This page gives a outline of how to use emacs lisp to do text processing, using a specific real-world problem as example. If you don't know...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.