hi..

i write this statement there is no errors but it not showing me the out put
this is the my code:

#include<fstream>
#include<iostream>

using namespace std;

int main()
{
	fstream infile;
	fstream outfile;

	infile.open( "classnames.txt",ios::in );
	outfile.open( "bufferednames.txt",ios::out );

	infile.unsetf( ios::skipws );

	int ch;

	for( int i=0; i<4; i++)
	{
		infile >> ch;

		while( ch != '\n' )
		{
			outfile << ch;
			infile  >> ch;

		}

		outfile << " - ";

	}

	infile.close();
	outfile.close();

	return 0;


}

i couldn't find the mistake..
please help..

You mean there is nothing in the output file? It is not supposed to show anything on the screen...

what do you mean???
no, i have created an input file with single names like:
AAAAA
BBBBB
CCCCCCC
DDD
EEEEE

and it suppose to output these names in one line separated with spaces..

If you just want to read from a file and print it to the output stream you can do

std::string line;
while(getline(infile,line)){
        std::cout << line << std::endl;
	//outfile << line << std::endl; or this to write to output file
}

did you try to run my programe??

u should then u will know the problem
i dont want to use getline() becase i just want 4 names for the output from an input file which can contain 20 or more names..

As Agni said, you need to be using cout if you want to see something on the screen. Also, you seem to be reading in the line as an int which doesn't make sense. You should read it as a std::string.

Also, you should not expect people to run your code. If they do, that is a great bonus, but you should try to explain your problem clearly enough that they do not have to run it to see what you are talking about.

As Agni said, you need to be using cout if you want to see something on the screen. Also, you seem to be reading in the line as an int which doesn't make sense. You should read it as a std::string.

Also, you should not expect people to run your code. If they do, that is a great bonus, but you should try to explain your problem clearly enough that they do not have to run it to see what you are talking about.

hhhhh..

thanks i found where is the mistake..

and sorry to tell u to run my programe,
i was exusted..
and thanks again..

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.