?
Solved

Beginner's Question: with statement in C++

Posted on 2000-04-28
4
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 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 clear a vector as well as how to detect empty vectors in C++.

719 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