Writing to a file

Posted on 2005-05-11
Last Modified: 2010-04-01
Hey everyone, I have a file containing numerical values ie:


I'm messing around with input and output files. Basically I have my program reading in the file with the above numbers in, and I wish ouput another file stating by "Y" or "N" If the values are above 50.

Here is my code:

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

int main()
   int num;
   ofstream outfile;
   ifstream infile;"numbers.txt");"outputs.txt");

   if (
      cout <<"Error opening file, program closing "<< endl;

while ( infile >> num )
       cout  <<  num << endl;

   cout <<"Checking numbers"<< endl;
  while ( infile >> num )
        if (num < 50)
      outfile << "N"  << "\t" ;  
        outfile << "Y" << "\t";

   return 0;

Although the program compiles and runs ok, it doesn't output anything to the output file. Can anyone help?

Question by:Helix
    1 Comment
    LVL 37

    Accepted Solution

    Hi Helix,

    Remove this part of the code...

     while ( infile >> num )
            cout  <<  num << endl;


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now