Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Beginner's Syntax Question

Posted on 1998-12-24
7
Medium Priority
?
178 Views
Last Modified: 2010-04-02
Assuming I have 3 variables v1, v2, v3, typically in VB I would be able to do stg like that to initialize them:

for a=1 to 3

v & a = x

next a

How do I do that in c++ assuming I cannot use v[1], v[2]...
The reason I am asking is that I have some variables attached to some controls, and the Class Viewer does not let me declare [] as part of a variable name.

Thanks & joyeux noel.
A.
0
Comment
Question by:decornez
[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
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:The_Brain
ID: 1181027
There is no Way of doing that in C++, you have to use arrays.

v[3]
for (int p=0; p<3; p++)
  v[p]=x;

this in way that you are asking is not an option in C++; sorry.

Regards Brain.
0
 

Author Comment

by:decornez
ID: 1181028
Sorry Brain,

unfortunately I know how to do that as well.
There's got to be a way somehow....
I'll leave this question open to see if anybody has any suggestions.

Thanks for the input and happy holidays.
A.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1181029
>> There's got to be a way somehow....
decornez, the C/C++ languages do not allow you to dynamically construct variable names.  No way around it due to the internal working of the languages.

You can write:
    v1 = v2 = v3 = x;

Or you can use arrays (as suggested by The_Brain).
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:The_Brain
ID: 1181030
if my answer is correct as it probably is can I have the points for it? if so could you send me an E-mail so that I can answer the question so that I may collect the points? or is this question gonna be one of those one that hang around to rot. :)
Brain.
0
 

Author Comment

by:decornez
ID: 1181031
Brain,

Merry Christmas. I'll give you the points since it seems that what I am trying to achieve is not doable anyway. Just post a comment and they are yours.

Rgds,
A.
0
 

Author Comment

by:decornez
ID: 1181032
Oooops, I meant post an answer (not comment) & they are yours.
0
 
LVL 1

Accepted Solution

by:
The_Brain earned 40 total points
ID: 1181033
Thanks man.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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++.
Suggested Courses

618 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