Solved

Beginner's Question: with statement in C++

Posted on 2000-04-28
4
206 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now