Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #5856 > unrolled thread
| Started by | A Moose in Love <parkstreetbooboo@gmail.com> |
|---|---|
| First post | 2011-05-30 17:20 -0700 |
| Last post | 2011-05-31 16:25 +0200 |
| Articles | 13 — 10 participants |
Back to article view | Back to comp.lang.c++
File Manipulation? A Moose in Love <parkstreetbooboo@gmail.com> - 2011-05-30 17:20 -0700
Re: File Manipulation? Ian Collins <ian-news@hotmail.com> - 2011-05-31 12:24 +1200
Re: File Manipulation? Öö Tiib <ootiib@hot.ee> - 2011-05-30 18:15 -0700
Re: File Manipulation? A Moose in Love <parkstreetbooboo@gmail.com> - 2011-05-30 19:22 -0700
Re: File Manipulation? Ian Collins <ian-news@hotmail.com> - 2011-05-31 14:33 +1200
Re: File Manipulation? John Smith <bit_bucket@gmx.com> - 2011-05-30 19:57 -0700
Re: File Manipulation? Liberian Freighter <parkstreetbooboo@gmail.com> - 2011-05-31 06:41 -0700
Re: File Manipulation? Geoff <geoff@invalid.invalid> - 2011-05-30 19:59 -0700
Re: File Manipulation? Geoff <geoff@invalid.invalid> - 2011-05-30 20:25 -0700
Re: File Manipulation? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-05-31 22:33 +0000
Re: File Manipulation? Miles Bader <miles@gnu.org> - 2011-06-01 15:07 +0900
Re: File Manipulation? Juha Nieminen <nospam@thanks.invalid> - 2011-05-31 08:25 +0000
Re: File Manipulation? "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2011-05-31 16:25 +0200
| From | A Moose in Love <parkstreetbooboo@gmail.com> |
|---|---|
| Date | 2011-05-30 17:20 -0700 |
| Subject | File Manipulation? |
| Message-ID | <c32da847-b415-4ba3-954c-e51ee8cbf5ff@e35g2000yqc.googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-05-31 12:24 +1200 |
| Message-ID | <94iqqaFr2iU13@mid.individual.net> |
| In reply to | #5856 |
On 05/31/11 12:20 PM, A Moose in Love 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'.
The code is fine. Are you sure you are looking in the correct place for
the fine?
--
Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Öö Tiib <ootiib@hot.ee> |
|---|---|
| Date | 2011-05-30 18:15 -0700 |
| Message-ID | <cf251945-cabd-4db5-b76f-db411c021658@a26g2000vbo.googlegroups.com> |
| In reply to | #5856 |
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.
[toc] | [prev] | [next] | [standalone]
| From | A Moose in Love <parkstreetbooboo@gmail.com> |
|---|---|
| Date | 2011-05-30 19:22 -0700 |
| Message-ID | <1bd4e783-6dbc-4eac-9255-3c8f71bedd0a@d28g2000yqf.googlegroups.com> |
| In reply to | #5858 |
On May 30, 9:15 pm, Öö Tiib <oot...@hot.ee> wrote:
> 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.
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.
"""
//under 9f = 2nd, 3rd, and last fracSplit = 1st, 2nd, and 3rd call
//@ 9f = 1st, 2nd, and last fracSplit = 1st, 2nd, and 3rd call
//for every 1/2f distance variation, punish or aid by 3/5 each
fracSplit
//for every 1f distance variation, punish or aid by 1 full second
//8.3 to 8.5 = 1/5 punished or aided
#include <iostream>
using namespace std;
double firstCall,secondCall,finalTime = 0;
double blFirst,blSecond,blFinal = 0;
double firstFraction,secondFraction,thirdFraction = 0;
double AP,EP,SP,FX,FW,TP,ELDiff = 0;
double EPEnergy,APEnergy,SPEnergy,FXEnergy,FWEnergy,ELDiffEnergy = 0;
double
EPSynthesis,APSynthesis,SPSynthesis,FXSynthesis,FWSynthesis,ELDiffSynthesis
= 0;
double lengthOfRace = 0;
double
energy,firstFractionEnergy,secondFractionEnergy,thirdFractionEnergy =
0;
double
firstFractionSynthesis,secondFractionSynthesis,thirdFractionSynthesis
= 0;
int trackVariant,routeMarker,horseNumber = 0;
bool correct = 0;
void lengthOfRaceFunction();
void enterData();
void fifthsToTenths();
void findFractions();
void trackVariantFunction();
void calculate();
void printData();
void five();
void fivePointFive();
void six();
void sixPointFive();
void seven();
void eight();
void eightPointTwo();
void eightPointThree();
void eightPointFive();
void nine();
//-------------------
int main()
{
cout.precision(4);
lengthOfRaceFunction();
system("PAUSE");
return EXIT_SUCCESS;
return 0;
}
//-------------------
void lengthOfRaceFunction()
{
//this function also calls all other functions
cout << "\nEnter Length Of Race(99 to quit): ";
cin >> lengthOfRace;
if (lengthOfRace == 99)
{
return;
}
if (lengthOfRace < 5 || lengthOfRace > 9)
{
cout << "\nWe don't do races less than 5 furlongs, ";
cout << "or greater than 9 furlongs. \n";
return;
}
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)
{
cout << "\ntryAgain!";
lengthOfRaceFunction();
}
enterData();
fifthsToTenths();
findFractions();
trackVariantFunction();
calculate();
printData();
lengthOfRaceFunction();
}
void enterData()
{
start:
cout << "\nEnter Horse Number: ";
cin >> horseNumber;
cout << "\nEnter First Call: ";
cin >> firstCall;
cout << "\nEnter Second Call: ";
cin >> secondCall;
cout << "\nEnter Final Time: ";
cin >> finalTime;
cout << "\nEnter Beaten Lengths First Call: ";
cin >> blFirst;
cout << "\nEnter Beaten Lengths Second Call: ";
cin >> blSecond;
cout << "\nEnter Beaten Lengths Final: ";
cin >> blFinal;
cout << "\nEnter Track Variant: ";
cin >> trackVariant;
cout << "\nis data correct?[Enter 1 for yes, 0 for no]";
cin >> correct;
while(!correct)
{
goto start;
}
}
void fifthsToTenths()
{
if (finalTime >= 100)
finalTime = finalTime - 40;
if (secondCall >= 100)
secondCall = secondCall - 40;
int firstCallInt = firstCall;
firstCall = firstCallInt + ((firstCall - firstCallInt) * 2);
int secondCallInt = secondCall;
secondCall = secondCallInt + ((secondCall - secondCallInt) * 2);
int finalTimeInt = finalTime;
finalTime = finalTimeInt + ((finalTime - finalTimeInt) * 2);
}
void findFractions()
{
int raceDistance = 0;
if (lengthOfRace == 5) raceDistance = 10;
if (lengthOfRace == 5.5) raceDistance = 9;
if (lengthOfRace == 6) raceDistance = 1;
if (lengthOfRace == 6.5) raceDistance = 2;
if (lengthOfRace == 7) raceDistance = 3;
if (lengthOfRace == 8) raceDistance = 4;
if (lengthOfRace == 8.2) raceDistance = 5;
if (lengthOfRace == 8.3) raceDistance = 6;
if (lengthOfRace == 8.5) raceDistance = 7;
if (lengthOfRace == 9) raceDistance = 8;
switch(raceDistance)
{
case 1:
six();
break;
case 2:
sixPointFive();
break;
case 3:
seven();
break;
case 4:
eight();
break;
case 5:
eightPointTwo();
break;
case 6:
eightPointThree();
break;
case 7:
eightPointFive();
break;
case 8:
nine();
break;
case 9:
fivePointFive();
break;
case 10:
five();
break;
}
}
void trackVariantFunction()
{
//normal 16 ---> 18
float variantPoints,variantPointsTwo = 0;
if (routeMarker == 5)
goto routes;
if (trackVariant > 18)
{
variantPoints = (trackVariant - 18) / 2;
finalTime = finalTime - (variantPoints * .2);
secondCall = secondCall - (variantPoints * .2) / 2;
}
if (trackVariant < 16 & trackVariant > 11)
{
variantPoints = (16 - trackVariant) / 2;
finalTime = finalTime + (variantPoints * .2);
secondCall = secondCall + (variantPoints * .2) / 2;
}
//when tv < 12 then variant points are doubled; 1:1
if (trackVariant < 12)
{
variantPoints = 2;
variantPointsTwo = 12 - trackVariant;
finalTime = finalTime + (variantPoints * .2) + (variantPointsTwo * .
2);
secondCall = secondCall + ((variantPoints * .2) + (variantPointsTwo
* .2)) / 2;
}
goto end;
//Routes:
routes:;
routeMarker = 0;
cout << "\nin routes" << endl;
if (trackVariant > 18)
{
variantPoints = (trackVariant - 18) / 2;
firstCall = firstCall - ((variantPoints * .2) / 2) * .67;
secondCall = secondCall - (variantPoints * .2) / 2;
finalTime = finalTime - (variantPoints * .2);
}
if (trackVariant < 16 & trackVariant > 11)
{
variantPoints = (16 - trackVariant) / 2;
firstCall = firstCall + ((variantPoints * .2) / 2) * .67;
secondCall = secondCall + (variantPoints * .2) / 2;
finalTime = finalTime + (variantPoints * .2);
}
//when tv < 12 then variant points are doubled; 1:1
if (trackVariant < 12)
{
variantPoints = 2;
variantPointsTwo = 12 - trackVariant;
firstCall = firstCall + ((variantPoints * .2) + (variantPointsTwo * .
2) / 2) * .67;
secondCall = secondCall + ((variantPoints * .2) + (variantPointsTwo
* .2)) / 2;
finalTime = finalTime + (variantPoints * .2) + (variantPointsTwo * .
2);
}
end:;
}
void calculate()
{
EP = ((firstFraction + secondFraction) - (10 * blSecond)) /
secondCall;
blFinal = blFinal - blSecond;
blSecond = blSecond - blFirst;
//VELOCITY!
firstFraction = (firstFraction - (blFirst * 10)) / firstCall;
secondFraction = (secondFraction - (blSecond * 10)) / (secondCall -
firstCall);
thirdFraction = (thirdFraction - (blFinal * 10)) / (finalTime -
secondCall);
SP = (EP + thirdFraction) / 2;
AP = (firstFraction + secondFraction + thirdFraction) / 3;
if (lengthOfRace > 7)
{
AP = (EP + SP) / 2;
}
FX = (firstFraction + thirdFraction) / 2;
ELDiff = EP - SP;
TP = ((firstFraction + secondFraction + thirdFraction) + EP) / 2;
FW = (((EP + thirdFraction) / 2) * EP) / 55;
//ENERGY!
energy = firstFraction + secondFraction + thirdFraction;
firstFractionEnergy = firstFraction / energy * 100;
secondFractionEnergy = secondFraction / energy * 100;
thirdFractionEnergy = thirdFraction / energy * 100;
EPEnergy = EP / energy * 100;
APEnergy = AP / energy * 100;
SPEnergy = (EPEnergy + thirdFractionEnergy) / 2;
FXEnergy = (firstFractionEnergy + thirdFractionEnergy) / 2;
FWEnergy = FW / energy * 100;
ELDiffEnergy = ELDiff / energy * 100;
//SYNTHESIS!
firstFractionSynthesis = ((firstFraction + firstFractionEnergy) / 2)
* 1.25;
secondFractionSynthesis = ((secondFraction + secondFractionEnergy) /
2) * 1.25;
thirdFractionSynthesis = ((thirdFraction + thirdFractionEnergy) / 2)
* 1.25;
EPSynthesis = ((EPEnergy + EP) / 2) * 1.25;
APSynthesis = ((APEnergy + AP) /2) * 1.25;
SPSynthesis = ((SPEnergy + SP) / 2) * 1.25;
FXSynthesis = ((FXEnergy + FX) /2) * 1.25;
FWSynthesis = ((FWEnergy + FW) /2) * 1.25;
ELDiffSynthesis = (ELDiffEnergy + ELDiff) / 2;
}
void printData()
{
cout.precision(4);
//cout << "\n\n*************************" << endl << endl;
cout << "Horse Number: " << horseNumber << endl;
cout << "TOTAL PACE: " << TP << endl;
cout << "\n____________________" << endl;
cout << "VELOCITY" << endl;
//cout << "\nfirstFraction: " << firstFraction << endl;
//cout << "secondFraction: " << secondFraction << endl;
//cout << "thirdFraction: " << thirdFraction << endl;
cout << "EP: " << EP << endl;
cout << "AP: " << AP << endl;
cout << "SP: " << SP << endl;
cout << "FW: " << FW << endl;
//cout << "FX: " << FX << endl;
cout.precision(3);
//cout << "ELDiff: " << ELDiff * 100 << endl;
cout << "____________________" << endl;
cout.precision(4);
cout << "\nENERGY" << endl;
cout << "\ntotal energy: " << energy << endl;
//cout << "firstFraction: " << firstFractionEnergy << endl;
//cout << "secondFraction: " << secondFractionEnergy << endl;
//cout << "thirdFraction: " << thirdFractionEnergy << endl;
cout << "EP: " << EPEnergy << endl;
cout << "AP: " << APEnergy << endl;
cout << "SP: " << SPEnergy << endl;
cout << "FW: " << FWEnergy << endl;
//cout << "FX: " << FXEnergy << endl;
cout.precision(3);
//cout << "ELDiff: " << ELDiffEnergy * 100 << endl;
cout << "____________________" << endl;
cout.precision(4);
cout << "\nSYNTHESIS" << endl;
//cout << "\ntotal energy: " << energy << endl;
//cout << "\nfirstFraction: " << firstFractionSynthesis << endl;
//cout << "secondFraction: " << secondFractionSynthesis << endl;
//cout << "thirdFraction: " << thirdFractionSynthesis << endl;
cout << "EP: " << EPSynthesis << endl;
cout << "AP: " << APSynthesis << endl;
cout << "SP: " << SPSynthesis << endl;
cout << "FW: " << FWSynthesis << endl;
//cout << "FX: " << FXSynthesis << endl;
cout.precision(3);
//cout << "ELDiff: " << ELDiffSynthesis * 100 << endl;
cout << "____________________" << endl;
//cout << "\n\n*************************" << endl << endl;
}
void five()
{
firstFraction = 1320;
secondFraction = 1320;
thirdFraction = 660;
}
void fivePointFive()
{
firstFraction = 1320;
secondFraction = 1320;
thirdFraction = 990;
}
void six()
{
firstFraction = 1320;
secondFraction = 1320;
thirdFraction = 1320;
}
void sixPointFive()
{
firstFraction = 1320;
secondFraction = 1320;
thirdFraction = 1650;
}
void seven()
{
firstFraction = 1320;
secondFraction = 1320;
thirdFraction = 1980;
}
void eight()
{
firstFraction = 2640;
secondFraction = 1320;
thirdFraction = 1320;
routeMarker = 5;
}
void eightPointTwo()
{
firstFraction = 2640;
secondFraction = 1320;
thirdFraction = 1440;
routeMarker = 5;
}
void eightPointThree()
{
firstFraction = 2640;
secondFraction = 1320;
thirdFraction = 1530;
routeMarker = 5;
}
void eightPointFive()
{
firstFraction = 2640;
secondFraction = 1320;
thirdFraction = 1650;
routeMarker = 5;
}
void nine()
{
firstFraction = 2640;
secondFraction = 1320;
thirdFraction = 1980;
routeMarker = 5;
}
"""
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-05-31 14:33 +1200 |
| Message-ID | <94j2brFr2iU15@mid.individual.net> |
| In reply to | #5862 |
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
[toc] | [prev] | [next] | [standalone]
| From | John Smith <bit_bucket@gmx.com> |
|---|---|
| Date | 2011-05-30 19:57 -0700 |
| Message-ID | <is1lea$i1g$3@dont-email.me> |
| In reply to | #5863 |
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
[toc] | [prev] | [next] | [standalone]
| From | Liberian Freighter <parkstreetbooboo@gmail.com> |
|---|---|
| Date | 2011-05-31 06:41 -0700 |
| Message-ID | <2cd75d2b-fb8a-43e2-a178-73a604ae3116@x3g2000yqj.googlegroups.com> |
| In reply to | #5863 |
On May 30, 10:33 pm, Ian Collins <ian-n...@hotmail.com> 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. > > -- > Ian Collins OK. Makes sense. I know where that is. Thanks.
[toc] | [prev] | [next] | [standalone]
| From | Geoff <geoff@invalid.invalid> |
|---|---|
| Date | 2011-05-30 19:59 -0700 |
| Message-ID | <3bm8u6p93odigc6ckp6ok6vg2s4eg6nb2h@4ax.com> |
| In reply to | #5862 |
On Mon, 30 May 2011 19:22:58 -0700 (PDT), A Moose in Love <parkstreetbooboo@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | Geoff <geoff@invalid.invalid> |
|---|---|
| Date | 2011-05-30 20:25 -0700 |
| Message-ID | <enn8u65aqsb0nj39vt3qv3mnciue2ofdgv@4ax.com> |
| In reply to | #5862 |
On Mon, 30 May 2011 19:22:58 -0700 (PDT), A Moose in Love
<parkstreetbooboo@gmail.com> 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();
}
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2011-05-31 22:33 +0000 |
| Message-ID | <slrniuar53.gtj.grahn+nntp@frailea.sa.invalid> |
| In reply to | #5862 |
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 .
[toc] | [prev] | [next] | [standalone]
| From | Miles Bader <miles@gnu.org> |
|---|---|
| Date | 2011-06-01 15:07 +0900 |
| Message-ID | <buod3iy6q59.fsf@dhlpc061.dev.necel.com> |
| In reply to | #5928 |
Jorgen Grahn <grahn+nntp@snipabacken.se> 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.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2011-05-31 08:25 +0000 |
| Message-ID | <4de4a5e9$0$2833$7b1e8fa0@news.nbl.fi> |
| In reply to | #5856 |
A Moose in Love <parkstreetbooboo@gmail.com> wrote:
> #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;
> }
Not related to your question, but I can't help but notice that you wrote
21 characters ("using namespace std;" plus the newline) in order to save
yourself from typing 5 characters ("std::"). A total "saving" of -16
characters. The program did not become any clearer that way (and, in fact,
some could argue that it became *less* clear this way). Not to talk that
now you have some tens or even hundreds of names polluting your global
namespace that don't need to be there.
Overall, seems rather counter-productive.
[toc] | [prev] | [next] | [standalone]
| From | "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> |
|---|---|
| Date | 2011-05-31 16:25 +0200 |
| Message-ID | <is2tob$u6c$1@news.albasani.net> |
| In reply to | #5856 |
"A Moose in Love" wrote in message
news:c32da847-b415-4ba3-954c-e51ee8cbf5ff@e35g2000yqc.googlegroups.com...
>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.
Several possibilities.
1) You are not looking at the right place. The file is created in the
directory where the program runs.
2) You don't check for errors. If the file cannot be created, (e.g., if the
device is read-only) the program does not warn you. Check the return values
and the state of the myfile object after each operation.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web