PDA

View Full Version : Is there anything wrong with this source code?




hotglass
Aug 9, 2008, 03:30 PM
The inFile was made in Word for Mac and it contains the number 5.50. When I run this, it is successful, yet there is just a blank output, where I want it to display the number 5.50.


#include <iostream>
#include <fstream>
using namespace std;

int main (int argc, char * const argv[])
{
double dec;
ifstream inFile;
inFile.open ("sample.txt");
inFile >> fixed >> showpoint;

inFile >> dec;

return 0;

}

This is the output:

Last login: Sat Aug 9 16:24:36 on ttys003
/Users/lucasmoderacki/sample/build/Release/sample ; exit;
macintosh:~ lucasmoderacki$ /Users/lucasmoderacki/sample/build/Release/sample ; exit;
logout

[Process completed]



lazydog
Aug 9, 2008, 05:24 PM
Hi

Aren't you missing:-


cout << dec << endl ;


or something like it?

Also you may want to use the full file path to sample.txt to avoid and ambiguity between your project and current directory.

b e n