Try this modified code:
#include <iostream>
#include <fstream>
using namespace std;
main()
{
char text_name[50];
char filename[50];
strcpy(filename,"/opt/css/roshan/utils/file/sample.txt");
ifstream instream(filename);
// instream.open(filename, ios_base::in);
instream.read(text_name,50);
instream.close();
cout << "\nThe Content of FILE is : " << text_name << endl;
}
Since you are using C++ (unlike C), you must use <iostream> instead of
<iostream.h>.
And also you must mention the namespace.
The way you used the ifstream was wrong. It will open the file by itself. So,
you don't need to open the file again.
Hope this works for you.
Regards,
Narendra
--- Selva Kumar <[EMAIL PROTECTED]> wrote:
> Hi ,
>
> There is a problem in sun solaris8 v880 machine.
> Our application in C++ reads a file using ifstream.
> The compiler we are using is
> /opt/SUNWspro/WS6U2/bin/CC
> This file stream function does not behave properly.It
> duplicates the first character in the file at the
> first position.
>
> Please find the following program that simulates the
> issue,
>
> #include <iostream.h>
> #include <fstream.h>
> #include <string.h>
> #include <unistd.h>
> #include <sys/mman.h>
> #include <iomanip.h>
> main()
> {
> char text_name[50];
> char filename[50];
> ifstream instream;
>
> strcpy(filename,"/opt/css/roshan/utils/file/sample.txt");
> instream.open(filename, ios_base::in);
> instream.read(text_name,50);
> instream.close();
> cout << "\nThe Content of FILE is : " <<
> text_name;
> }
>
> The input file content are as follows,
>
> [/opt/css/roshan/utils/file]>$cat *.txt
> This is a TEST Message
> This contains Data
>
> The output of the program is as follows,
>
> [/opt/css/roshan/utils/file]>$./a.out
> The Content of FILE is : TThis is a TEST Message
> This contains Data
>
> Can any one tell us why there is a duplication
> [TThis] in the out put.
>
> Regards,
> Selva
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
> _______________________________________________
> Solaris-Users mailing list
> [email protected]
> http://www.filibeto.org/mailman/listinfo/solaris-users
>
Warm Regards,
S.S.Narendra Kumar
___ ___ __ _
/ __/ __ / | //
_\ \ \ \ / /||//
\___/___//_/ |_/
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Solaris-Users mailing list
[email protected]
http://www.filibeto.org/mailman/listinfo/solaris-users