Re: Need help with a Work around

From: kazack (kazack_at_talon.net)
Date: 10/29/03


Date: Wed, 29 Oct 2003 07:06:08 GMT

Oh my god. I was looking at your code and said I tried that and it didn't
work I kept getting this error:
----------------------------------------------------------------------------
----------------------------------------
error C2664: 'void __thiscall std::basic_ifstream<char,struct
std::char_traits<char> >::open(const char *,int)' : cannot convert parameter
1 from 'const char *(void) const' to 'const char *'
        There is no context in which this conversion is possible
----------------------------------------------------------------------------
----------------------------------------
And now I know why. The reason is with the .c_str I didn't have the ()
after it to make it look like this filename.c_str() So I did have the right
concept but just a syntax thing going on!!! Thank you so much.

The reason for the _access is because everythign I have been reading it
tells me you can only check to see if the file can be opened, if it can not
be opened it can not be determined what the specific problem is. I don't
want to say file don''t exist when it actualy does and have someone
overwrite data in a file where the file may be saveable. So I wanted to
make sure the file was or was not there before giving the user other options
like create a new file, select another file name just in case they typed in
the wrong file name, etc.

But thank you so much for your generous reply. If interested when I am done
with with my overboard for this problem I will post the code in full!!! I
don't think the code will be too bad for someone learning c++ and in it only
about a month!! The book has 18 chapters and I am going to after this going
intochapter 11. Which I am not looking forward to which is the use of
structure types, Data Abstraction and classes. I think I could actually
skip that whole chapter and leave it for if I were to work on someone elses
code that uses it. I can do the same thing without them, my code would
prolly be a bit more indepth and longer than using them but atleast it would
actually make sense when you look at the code!!! I don't know I'll see when
I start reading the material and actually see code in use and study it to
learn what is going on.

But anyways thanks alot for the help, I can't believe I actually had it
right when I tried doing it myself but had the wrong syntax. Oh well I
guess these things happen to the best of us!!!!

Shawn Mulligan

"Davlet Panech" <sp@mmers.rot-in-hell> wrote in message
news:cPHnb.3094$Nm6.213345@news20.bellglobal.com...
> >[...]
> >
> > 01 #include <iostream>
> > 02 #include <fstream>
> > 03 #include <string>
> > 04 #include <io.h>
> > 05 #include <cstring>
> > 06 using namespace std;
> > 07 enum Triangles
>
> This is a syntax error. I assume you pasted your code without looking.
>
> > 08 void main()
>
> int main ()
>
> > 09 {
> > 10 ifstream inData;
> > 11 const char* filename = "filename.dat";
>
> string filename;
> cout << "Please Enter The Data File You Would Like To Use: ";
> cin >> filename;
>
> > 12 if ((_access(filename,0))!=-1)
>
> if ((_access(filename.c_str (),0))!=-1)
>
> > 13 {
> > 14 cout << filename << " Exists\n";
> > 15 }
> > 16 else
> > 17 {
> > 18 cout << filename << " Does Not Exist\n";
>
> Add (after "cout..."):
>
> return 1;
>
> > 19 }
> > 20 inData.open(filename);
>
> inData.open(filename.c_str ());
> if (!inData)
> {
> cout << filename << " could not be opened" << endl;
> return 1;
> }
>
> Also, add "return 0;" at the end of "main()" (hint: "main()" should return
0
> if your program finished without errors).
>
> Another thing, you don't really have to use the "_access()" function. You
> can just try to open the file, and print an error message if you can't
(one
> of the reasons for this could be that the file does not exist).
>
> D.
>
>



Relevant Pages

  • Re: fortran reading a line
    ... note also that reading 1e2 in %d format is not an error in C. ... It seems to me that just having a feature doesn't need to ... that would be a good reason to add it? ...
    (comp.lang.fortran)
  • [HPADM] [SUMMARY] ERROR bad magic number/system id for dld.sl
    ... It looks like it was a time-out while reading the file, ... last week because of the named reason. ... Krankenhaus Mara gGmbH. ...
    (HP-UX-Admin)
  • Re: Hidden Tables
    ... I was reading some code and it contained a 'DoCmd.TransferDatabase", ... However when I examined the server database I did not see the table that was ... This was my first time using the debugger and I found it to meet all my ... The most important reason for me to hide objects, ...
    (comp.databases.ms-access)
  • Re: Betovs notation
    ... That might apply to RosAsm... ... >:)) You just give the reason why an Assembler should NEVER ... That's not Nasm syntax, maybe it's LuxAsm syntax... ... > the readability, ... ...
    (alt.lang.asm)
  • Re: eBook Ignoramus Authors
    ... In any case, that's less than 100 words, which is a few seconds of reading. ... but nevertheless when corrected have no trouble with reading screens. ... permit as high a resolution as you like, allows both visual overlay and straight display, etc. There's a reason I chose that as A.J. Baker's preferred viewing method. ...
    (rec.arts.sf.written)