Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Beginner's Question: with statement in C++

Posted on 2000-04-28
4
Medium Priority
?
246 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 100 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

916 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