Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: File Manipulation?

Reply
Thread Tools

Re: File Manipulation?

 
 
Öö Tiib
Guest
Posts: n/a
 
      05-31-2011
On May 31, 3:20*am, A Moose in Love <parkstreetboo...@gmail.com>
wrote:
> I need to know in a simple way, how to create files, open them, write
> to them, save them, and close them. *I've googled and have come up
> with information that doesn't seem to work. *For example:
> // basic file operations
> #include <iostream>
> #include <fstream>
> using namespace std;
>
> int main () {
> * ofstream myfile;
> * myfile.open ("example.txt");
> * myfile << "Writing this to a file.\n";
> * myfile.close();
> * return 0;
>
> }
>
> This does not work. *I cannot find a file after running this little
> program called 'example.txt'.
> I'm not a programmer; I just need to do this.


Being not a programmer is OK, but do you at least know what operating
system and C++ compiler you are using? With that information available
people might be able to help you to find that "example.txt" of yours.
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      05-31-2011
On 05/31/11 02:22 PM, A Moose in Love wrote:
>> people might be able to help you to find that "example.txt" of yours.

>
> I looked for the file. I opened 'Control Panel' and searched. I
> have Windows XP.


The file will be in the directory where you ran the programme. If you
don't know where that is, try asking on a group or forum dedicated to
your IDE.

--
Ian Collins
 
Reply With Quote
 
 
 
 
John Smith
Guest
Posts: n/a
 
      05-31-2011
On 5/30/2011 7:33 PM, Ian Collins wrote:
> On 05/31/11 02:22 PM, A Moose in Love wrote:
>>> people might be able to help you to find that "example.txt" of yours.

>>
>> I looked for the file. I opened 'Control Panel' and searched. I
>> have Windows XP.

>
> The file will be in the directory where you ran the programme. If you
> don't know where that is, try asking on a group or forum dedicated to
> your IDE.
>


1) Open up a command prompt (emulated dos prompt.)

The command prompt should be in you accessories directory.

2) Change to the root of the drive with:

cd \

3) Enter:

dir filename.exe /s

Make sure you replace "filename.exe" with the name of the file you are
looking for. Let the above command complete, you should see text
telling you where the file is, or that file was not found. If you are
in the root, it has scanned the whole disk and that filename.exe dos not
exist on the drive.

Regards,
JS

 
Reply With Quote
 
Geoff
Guest
Posts: n/a
 
      05-31-2011
On Mon, 30 May 2011 19:22:58 -0700 (PDT), A Moose in Love
<> wrote:

>I looked for the file. I opened 'Control Panel' and searched. I
>have Windows XP. I use for a compiler, I use Bloodshed Dev - C++
>4.9.9.2. Here is my source code for the program in question. (if
>that helps?)
>This is a program to analyze pace as pertains to horse racing.


[snip code for brevity]

Nowhere in your code does a file get opened or written.
 
Reply With Quote
 
Geoff
Guest
Posts: n/a
 
      05-31-2011
On Mon, 30 May 2011 19:22:58 -0700 (PDT), A Moose in Love
<> wrote:

>I looked for the file. I opened 'Control Panel' and searched. I
>have Windows XP. I use for a compiler, I use Bloodshed Dev - C++
>4.9.9.2. Here is my source code for the program in question. (if
>that helps?)
>This is a program to analyze pace as pertains to horse racing.


You never write a file.
Using your printData function as a model, create a writeData function
replacing all your cout with myfile and call it from your
lengthOfRaceFunction. Now you will need to write some kind of inteface
for getting user input for specifying the file names.

void writeData()
{
ofstream myfile;
myfile.open ("example.txt");
cout << "Writing data file." << endl;

myfile.precision(4);
//write << "\n\n*************************" << endl << endl;
myfile << "Horse Number: " << horseNumber << endl;

myfile << "TOTAL PACE: " << TP << endl;

myfile << "\n____________________" << endl;
myfile << "VELOCITY" << endl;
//myfile << "\nfirstFraction: " << firstFraction << endl;
//myfile << "secondFraction: " << secondFraction << endl;
//myfile << "thirdFraction: " << thirdFraction << endl;
myfile << "EP: " << EP << endl;
myfile << "AP: " << AP << endl;
myfile << "SP: " << SP << endl;
myfile << "FW: " << FW << endl;
//myfile << "FX: " << FX << endl;
myfile.precision(3);
//myfile << "ELDiff: " << ELDiff * 100 << endl;
myfile << "____________________" << endl;

myfile.precision(4);
myfile << "\nENERGY" << endl;
myfile << "\ntotal energy: " << energy << endl;
//myfile << "firstFraction: " << firstFractionEnergy << endl;
//myfile << "secondFraction: " << secondFractionEnergy << endl;
//myfile << "thirdFraction: " << thirdFractionEnergy << endl;
myfile << "EP: " << EPEnergy << endl;
myfile << "AP: " << APEnergy << endl;
myfile << "SP: " << SPEnergy << endl;
myfile << "FW: " << FWEnergy << endl;
//myfile << "FX: " << FXEnergy << endl;
myfile.precision(3);
//myfile << "ELDiff: " << ELDiffEnergy * 100 << endl;
myfile << "____________________" << endl;

myfile.precision(4);
myfile << "\nSYNTHESIS" << endl;
//myfile << "\ntotal energy: " << energy << endl;
//myfile << "\nfirstFraction: " << firstFractionSynthesis <<
endl;
//myfile << "secondFraction: " << secondFractionSynthesis <<
endl;
//myfile << "thirdFraction: " << thirdFractionSynthesis << endl;
myfile << "EP: " << EPSynthesis << endl;
myfile << "AP: " << APSynthesis << endl;
myfile << "SP: " << SPSynthesis << endl;
myfile << "FW: " << FWSynthesis << endl;
//myfile << "FX: " << FXSynthesis << endl;
myfile.precision(3);
//myfile << "ELDiff: " << ELDiffSynthesis * 100 << endl;
myfile << "____________________" << endl;
//myfile << "\n\n*************************" << endl << endl;

myfile.close();
}
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      05-31-2011
On Tue, 2011-05-31, A Moose in Love wrote:
....
> 4.9.9.2. Here is my source code for the program in question. (if
> that helps?)
> This is a program to analyze pace as pertains to horse racing.
>
> """

....

>
> void lengthOfRaceFunction()
> {

....
> if (lengthOfRace != 5 & lengthOfRace != 5.5 & lengthOfRace != 6 &
> lengthOfRace != 6.5 & lengthOfRace !=7 &
> lengthOfRace != 8 & lengthOfRace != 8.2 & lengthOfRace != 8.3 &
> lengthOfRace != 8.5 & lengthOfRace != 9)


I haven't read all of it (it was kind of hard to read), but two
obvious bugs:

- you can't reliably use != on doubles
- don't confuse the '&&' and the '&' operators

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Miles Bader
Guest
Posts: n/a
 
      06-01-2011
Jorgen Grahn <grahn+> writes:
> - you can't reliably use != on doubles


Of course one shouldn't do so blindly, but there are certainly cases
where it makes sense to use != or == on doubles.

E.g., comparison of doubles holding integral values that result from an
explicit assignment should be fine (double d = 47; .... if (d != 47) ).
This is very useful for detecting explicitly assigned out-of-band (for
the algorithm) values.

[I guess some fractional values (e.g. 0.5) should in practice also be OK
since they're exactly representable in any sane radix (2, 10, 16).]

-Miles

--
Consult, v.i. To seek another's disapproval of a course already decided on.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting JPG file ppt file [Powerpoint] file zxcvar Digital Photography 7 06-22-2009 07:54 PM
Reading of file by next of map file and by next of file descriptor. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki C++ 1 07-10-2007 02:46 AM
How to create MDF file (.mdf) file from XML file. Dave ASP .Net 1 06-07-2007 11:32 PM
In file parsing, taking the first few characters of a text file after a readfile or streamreader file read... .Net Sports ASP .Net 11 01-17-2006 12:44 AM
An Automated process of watching a network file folder, reading a file in it and deleting the file using ASP.NET ? Luis Esteban Valencia Muñoz ASP .Net 3 06-04-2005 10:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57