problem with get as text

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
closed account (zb0S216C)
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:
10 100 1000


Wazzak
Last edited on
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?

Don't include namespace std.
closed account (zb0S216C)
Knight0black wrote:
i copy - paste your program and got this 5 error

The code worked perfectly fine in VC++ 2010. Strange. Post the code you have currently.

Wazzak
It is because knight0black is using an old C++ compiler (pre-standard). Upgrade your compiler.
http://www.cplusplus.com/forum/windows/30574/#msg168096
no i dont i use c++ builder 6
C++ Builder 6 is out of date, and has significant issues.
Upgrade your compiler.
then how about visual studio 2008???
That would be better, yes.
visual studio 2008 some of the order of c++ don't run.
Last edited on
Topic archived. No new replies allowed.