I'm cryptically told nothing more then "your code is almost completely wrong"
this is supposed to be a program that reads from an input file (infile.dat) one line of "programming advice" to a user. Then the user enters their own advice for the next person who runs the program to see. When you're done entering the advice supposedly you press enter twice to end the program

Not looking for someone to just give me code...just looking to understand what I'm doing so wrong -_-

thanks

#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main (void)
{
	string first, words;

	ifstream in_stream;
	ofstream out_stream;

	in_stream.open("infile.dat");

	if (in_stream.fail())
	{
		cout << "Input file opening failed" << endl;
		exit(1);
	}

	out_stream.open("infile.dat");
	if (out_stream.fail())
	{
		cout << "Output file opening failed" << endl;
		exit(1);
	}

	cout << "Press enter to see some advice to help you with programming" << endl;

	getline (cin, first);

	cout << first << endl;
	cout << "Now enter some advice for the next person to see this" << endl;

	do 
     { 
          getline (cin, words); 
          out_stream.put (words); 
     }
    while (words != '/n');

	in_stream.close();
	out_stream.close();
	
	system ("pause");
	return 0;
}

you can't input and output to the file at the same time without some very fancy footwork by repositioning the file pointer to the beginning of the file before the write. The way I understand what you want, the file only contains one line of text, which you want to change each time you run the program. The simplest way to do that

open input file
read the line of text
close input file
open output file, with ios::truncate flag so that the current line is erased.
write new line of text to the file
close output file

Notice that it is not necessary to have both input and output files opened at the same time.

Hope this helps :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.