Error in opening a file C++


 
Thread Tools Search this Thread
Top Forums Programming Error in opening a file C++
# 1  
Old 12-11-2009
Question Error in opening a file C++

Hi,
I have written a function which will open the file with the input name provided.Input name is in string format so while opening I am converting it using c_str().detail code below Plz let me know what is the wrong in code.

Code:
 
      1  #include<iostream>
      2  #include<fstream>
      3  #include<string>
      4  #include<stddef.h>
      5  #include<cstddef>
      6  #include<cstring>
      7
      8  using namespace std;
      9
     10  int main ()
     11 {
     12 string file1,file2;
     13 string file3;
     14
     15 fstream OpenFile(string,ios_base::openmode);
     16
     17 cout << "Enter File Names"<<"\n";
     18 getline(cin,file1);
     19 getline(cin,file2);
     20 getline(cin,file3);
     21
     22 ifstream INPUT1;
     23 fstream INPUT2;
     24 ofstream INPUT3;
     25
     26 INPUT1 =  OpenFile(file1, ios::in | ios::binary);
     27 INPUT2 =  OpenFile(file2, ios::in);
     28 INPUT3 = OpenFile (file3, ios::out);
     29
     30
     31 INPUT1.close();
     32 INPUT2.close();
     33 INPUT3.close();
     34
     35 return 0;
     36 }
     37
     38      fstream OpenFile (string filename, ios_base::openmode mode)
     39     {
     40          fstream file;
     41
     42         file.open (filename.c_str(), mode);
     43         return file;
     44     }

# 2  
Old 12-11-2009
What error do you get? Which OS? Which compiler?
# 3  
Old 12-11-2009
Some part of the Error is & same follows for remaining lines as well.

Code:
 
ex.cpp: In function `int main()':
ex.cpp:26: error: no match for 'operator=' in 'INPUT1 = OpenFile(std::string, std::_Ios_Openmode)(std::operator|( _S_in,  _S_bin))'
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/iosfwd:90: note: candidates are: std::basic_ifstream<char, std::char_traits<char> >& std::basic_ifstream<char, std::char_traits<char> >::operator=(const std::basic_ifstream<char, std::char_traits<char> >&)
ex.cpp: In copy constructor `std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)':
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/bits/ios_base.h:781: error: `std::ios_base::ios_base(const std::ios_base&)' is private

Compiling on a Linux box using g++ compiler.
# 4  
Old 12-11-2009
The first error is the same one as in your other thread.

The second error is pretty self-explaining: you're trying to access a private property from outside the class, which is forbidden by data encapsulation.
# 5  
Old 12-11-2009
Thanks Pludi for ur continues reply.
If you look at the code written I have not used any classes or any member as private.

Would it be possible for u to give me the solutions for this problem?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

LibGL error when opening GUI version of MATLAB

Hi all, Today, I have a question regarding a libGL error. Currently, I access linux server by using the terminal application in MAC. However, when I try to use GUI version of MATLAB, I have faced an error message as shown below. libGL error: No matching fbConfigs or visuals found libGL... (1 Reply)
Discussion started by: syg3434
1 Replies

2. AIX

Opening a file in vi editor is giving out of memory error

Below is the error: Out of memory saving lines for undo - try using ed : Please help me how do I open this file. Best regards, Vishal (5 Replies)
Discussion started by: Vishal_dba
5 Replies

3. Shell Programming and Scripting

Opening a file in vi and automatically save and quit this file using shell script

Hi friends, In my shell script, I want to open a file using vi editor. After opening the file in vi, I want to save and quit this file automatically.... all through shell script. the code segment is: ------------------------------------------------------------ cd ~/netfpga/projects/scone/sw/... (2 Replies)
Discussion started by: sachinteotia
2 Replies

4. Solaris

Library error while opening firefox

I have Solaris-10 zone, where I can open firefox in GUI via MobaXterm with root user, but when I try to open it with non root user, it fails with below error $ which firefox /usr/bin/firefox $ firefox ld.so.1: firefox-bin: fatal: relocation error: file... (6 Replies)
Discussion started by: solaris_1977
6 Replies

5. AIX

Error opening device: /dev/fscsi0

Hello, One one of my AIX boxes I'm having the following errror: fcstat fcs0: Port Speed (supported): 4 GBIT Error opening device: /dev/fscsi0 errno: 0000003d Has anyone encountered similar errors? Thank you! (1 Reply)
Discussion started by: aixn00b
1 Replies

6. Solaris

Very Importan - Vim Settings - Error while opening a File using vim

I downloaded vim.7.2 and compiled the vim source . Added the vim binary path to PATH (Because iam not the root of the box) when i load the file using vim it throws me an error Error detected while processing /home2/e3003091/.vimrc: line 2: E185: Cannot find color scheme darkblue line... (0 Replies)
Discussion started by: girija
0 Replies

7. Windows & DOS: Issues & Discussions

Error opening script file - location error

Hello, I know nothing about UNIX, ftp, etc. I am building an excel VBA macro which calls a .bat file. I've taken a pre-existing batch file and am trying to modify it to fit my purposes. I would be very grateful for some assistance. Here is my .bat file: echo off set... (9 Replies)
Discussion started by: starcraftbud
9 Replies

8. Windows & DOS: Issues & Discussions

error opening website

hi I have unusual problem you might say. I can't open microsoft.com , I've checked file hosts located somewhere in windows/system32/drivers .. and its not blocked from there, what else could cause this problem, I need to download microsoft visual studio and I can't cause I can't open the website,... (1 Reply)
Discussion started by: c0mrade
1 Replies

9. Programming

Error found while opening any pdf file from IE 6

Hello All, My application is followed J2ee architecture. It contains Java and jsp codes. This application generates some reports in pdf format. I am using Weblogic 10.3 and jdk 6. While I want to open the pdf in IE 6 with service pack 2 , the pdf not showing properly. It comes in byte code.... (3 Replies)
Discussion started by: priyankak
3 Replies

10. Shell Programming and Scripting

error while opening files in a directory

I tried opening the files in a directory and print thier names. But it was thowing the error "unable to open directorty at t5.pl line 2." Can u plz correct this error in below mentioned code. #!/data/scoredev/perl opendir(HOMEDIR,"c:\vin") || die("unable to open directorty");... (3 Replies)
Discussion started by: vinay123
3 Replies
Login or Register to Ask a Question