Jun 6, 2011 at 11:38am UTC
hello.
I found how to write on .txt in tutorial and now i want to
get data on .txt on the screen.
how do i do this? please explanation.
tanks for your future help
Jun 6, 2011 at 2:20pm UTC
Knight0black wrote:now i want to get data on .txt on the screen.
Assuming you do actually know how to write to a file, reading from a file is just as easy. Here's an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include <fstream>
#include <iostream>
void read_file( const char *pfile )
{
if ( !pfile )
return ;
std::ifstream stream;
stream.open( pfile );
if ( !stream.is_open( ) )
return ;
int buf[ 3 ] = { 0 };
for ( int pass( 0 ); pass < 3; pass++ )
{
stream >> buf[ pass ];
std::cout << "Extracted number: " << buf[ pass ] << std::endl;
}
stream.close( );
}
int main( )
{
read_file( "SampleFile.txt" );
return 0;
}
Here's the text file I was reading from:
Wazzak
Last edited on Jun 6, 2011 at 2:21pm UTC
Jun 15, 2011 at 7:07pm UTC
hello Mr framework
i copy - paste your program and got this 5 error
1- quantifier 'std' is not a class or namespace name (9,8)
2- missing ; (9,10)
3- undefined symbol 'stream' (11,12)
4- quantifier 'std' is not a class or namespace name (20,12)
5- missing ; (20,14)
now what i'm gonna do for error?
Jun 15, 2011 at 8:19pm UTC
Don't include namespace std.
Jun 16, 2011 at 10:57am UTC
no i dont i use c++ builder 6
Jun 16, 2011 at 1:11pm UTC
C++ Builder 6 is out of date , and has significant issues.
Upgrade your compiler.
Jun 16, 2011 at 1:46pm UTC
then how about visual studio 2008???
Jun 16, 2011 at 3:07pm UTC
That would be better, yes.
Jun 16, 2011 at 3:13pm UTC
visual studio 2008 some of the order of c++ don't run.
Last edited on Jun 16, 2011 at 3:21pm UTC