Hello!
I would like to read in a list of data into my program instead of keyboard
input. How does one do this?
Regards,
Brad Fonseca
I would like to read in a list of data into my program instead of keyboard
input. How does one do this?
Regards,
Brad Fonseca
Open a file and read it.Quote:>Hello!
>I would like to read in a list of data into my program instead of keyboard
>input. How does one do this?
If you look in the MSL C or the MSL C++ references you will see how to
do this. If I knew if you wanted C or C++ I could give you more info.
Ron
--
CodeWarrior for Macintosh, v7 and CodeWarrior for Windows, v7
are shipping now !!
Call 1-800-377-5416 US and Canada Only
Sorry, I'm working on a C project. Where are the MCL C and MCL C++
references?
Thanks,
Brad Fonseca
> >Hello!
> >I would like to read in a list of data into my program instead of
keyboard
> >input. How does one do this?
> Open a file and read it.
> If you look in the MSL C or the MSL C++ references you will see how to
> do this. If I knew if you wanted C or C++ I could give you more info.
> Ron
> --
> CodeWarrior for Macintosh, v7 and CodeWarrior for Windows, v7
> are shipping now !!
> Call 1-800-377-5416 US and Canada Only
Brad, Try this code:
#include <fstream.h>
int a;
fstream data;
data.open("filename.txt",ios::in);
data >> a;
data.close();
I've taught C++ using Codewarrior to high school students for 6 years
now and have figured out a lot of these mysteries. Let me know if I
can help you in any other way.
Bill
> I would like to read in a list of data into my program instead of keyboard
> input. How does one do this?
> Regards,
> Brad Fonseca
Many Thanks,
Brad
> Brad, Try this code:
> #include <fstream.h>
> int a;
> fstream data;
> data.open("filename.txt",ios::in);
> data >> a;
> data.close();
> I've taught C++ using Codewarrior to high school students for 6 years
> now and have figured out a lot of these mysteries. Let me know if I
> can help you in any other way.
> Bill
> > Hello!
> > I would like to read in a list of data into my program instead of
keyboard
> > input. How does one do this?
> > Regards,
> > Brad Fonseca
> --
> Bill Eifert, Computer Science Dept, Princeton High School
> 11080 Chester Road
> Cincinnati, OH 45040
It's C++, not C. The code for an entire short program is:
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
void main(void)
{ // begin main
// declarations
double Fahrenheit, Celsius;
// open the data file
fstream data;
data.open("Temperatures.txt",ios::in);
if (!data)
{ // begin error message
cout << "The file could not be opened." << endl;
cout << "No data will be processed." << endl;
exit(1);
} // end error message
// process all values in the data file
while (data >> Fahrenheit)
{ // begin processing all values
// calculate the Celsius temperature
Celsius = 5./9. * (Fahrenheit - 32);
// display answers
cout << Fahrenheit << "? F = " << Celsius << "? C" << endl;
} // end processing all values
// close the data file
data.close();
The data file Temperatures.txt should contain one double value per line.Quote:} // end main
Hope this helps.
Bill Eifert
> #include <fstream.h>
> int a;
> fstream data;
> data.open("filename.txt",ios::in);
> data >> a;
> data.close();
> I've taught C++ using Codewarrior to high school students for 6 years
> now and have figured out a lot of these mysteries. Let me know if I
> can help you in any other way.
> Bill
> > Hello!
> > I would like to read in a list of data into my program instead of keyboard
> > input. How does one do this?
> > Regards,
> > Brad Fonseca
You might want to check the chapters in MSL C++ Reference the items inQuote:>Is this C code or C++? Where should it go in the code? Within the main
>function (except #include <fstream.h>)? Do you have a simple example I could
>try?
Ron
--
GeekWare !!!
http://www.metrowerksstore.com/metrowerks/geekware.html
<snip code>Quote:> [[ This message was both posted and mailed: see
> the "To," "Cc," and "Newsgroups" headers for details. ]]
> It's C++, not C. The code for an entire short program is:
> #include <iostream.h>
> #include <iomanip.h>
> #include <fstream.h>
> void main(void)
> { // begin main
I'm no expert, but I thought main() always has a return type of int
(at least in C++)?
Woody
> > It's C++, not C. The code for an entire short program is:
> > #include <iostream.h>
> > #include <iomanip.h>
> > #include <fstream.h>
> > void main(void)
> > { // begin main
> <snip code>
> I'm no expert, but I thought main() always has a return type of int
> (at least in C++)?
> Woody
int return of main is required by the C/C++ standards. Any code whichQuote:>It doesn't have to. Returning void is less confusing for beginning
>programming students --- no need for a return at the end of main.
>However, I think that the Mac version of Codewarrior does return an
>integer return type for main -- but the windows version doesn't.
hth
meeroh
--
Hire me: <http://meeroh.org/hire.html>
Actually it is more confusing as it is not legal The standards both CQuote:>It doesn't have to. Returning void is less confusing for beginning
>programming students --- no need for a return at the end of main.
The standards also say if there isn't an explicit return for main itQuote:>However, I think that the Mac version of Codewarrior does return an
>integer return type for main -- but the windows version doesn't.
Ron
--
GeekWare !!!
http://www.metrowerksstore.com/metrowerks/geekware.html
1. Setting a .csv file or .txt file to read only using SAS code
Hi all!
I was wondering if there was a way to set a .csv file to READ ONLY using SAS
code.
Tonya
3. Reading a txt-file with 'squares' (hexadecimal values)
4. GEAR / GEAR MM? Whats the Difference?
5. Reading large .txt file help!
7. K95 send matches file.txt~ to *.txt
9. Data in pdf-forms -> excel or tab-separated txt files
10. : Extracting data to a Flat .txt file
11. How to read input data with my printer driver
12. Save a File From a Macro as a TXT file without an File Extension
13. Reading Input into WinRunner From an External File