Solved

Beginner's Question: with statement in C++

Posted on 2000-04-28
4
214 Views
Last Modified: 2010-05-18
I recently migrate from Pascal. But I can't find anything like the Pascal "with" statement in the C++ online help. How to do this in C++?
0
Comment
Question by:sccheung
4 Comments
 
LVL 1

Expert Comment

by:David MacDonald
ID: 2761512
What was the "with " statement doing?...
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 50 total points
ID: 2761590
Or, in C/C++ no "with" statement.
Whan can be equivalent?
If you use some structure/class/pointer, you use "->"/"."
  contsruction.
In Pascal: (psevdocode)

with MyFile
  .Open
  .read
  .Close
End with

In C++
  ifstream in("myfile.dat");
  in.getline(...);

or MyClass *myClass;

  myClass->Open(...);
  myClass->read();
  myClass->Close();

I hope, it helps. Alex
0
 
LVL 22

Expert Comment

by:nietod
ID: 2762038
yeah, there really is no equivalent, which is actually good. Pascal's with statement was a mistake that leads to confussion an problems.  This one of the rare times when C++ has a syntractic advantage of Pascal

In a sense, C++'s member functions are similar to Pascal's "with".  This is because a member fucntion can access all the data members of an object (class or structure) without having to explicitly dereference the "this" pointer to get to the data members.
0
 

Author Comment

by:sccheung
ID: 2763484
It's fine. I can use copy and paste instead. But since the answer didn't "solve" the question, (because there is no solution in this case) I can't give a very high grade.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 101
sorting efficency of sorting algorithm 30 113
Unable to start eclipse ? 17 141
Embarcadero C++ builder XE10.1 Berlin TRegistry declaration 1 29
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question