473,414 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Incrementation impossible?

Having read over some of the disscussions involving incrementing variable names in C++, I have the impression that it's impossible. Is that true? I have a very definite need for them in the following program, and an array won't work. I need to read over a file and store certain information in a struct (person dave; dave.money=200 etc.). However, to stay true to the spec I shouldn't assume that there will always be x many entries I need to store. This means I should have a dynamic amount of struct declarations, and this seems impossible to me.

Is there any way to do this?

The struct:
Expand|Select|Wrap|Line Numbers
  1. struct person{
  2. string name;
  3. vector<string> repnames;
  4. int money;
  5. int togive;
  6. };
What I need to do:

Expand|Select|Wrap|Line Numbers
  1. void readloop(int othernumber, fstream &niceinfile, vector<string>namespace2, int count){
  2.     person dave;
  3.     input>>dave.name;
  4.     input>>dave.money;
  5.     input>>dave.togive;
  6. }
...Except change dave to S1-x, or anything else that will work. Can I use c_str() to do this, maybe? I'm at a loss for what to do here.
Mar 1 '07 #1
3 1690
Ganon11
3,652 Expert 2GB
You can create a vector of structs. Every time you need a new person, use .push_back() to add him to the vector, then initialize the variables normally.
Mar 1 '07 #2
Thanks, that works. I can't believe I was dim enough not to know I could just make an array of my struct! Thanks for the help.
Mar 2 '07 #3
Ganon11
3,652 Expert 2GB
No problem - just glad I could help!
Mar 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Piotre Ugrumov | last post by:
I have tried to modify my exercise about the simulation of the life in the savannah. Now I have only 2 errors but I don't comprehend how resolve these errors. If I try to call the method getX() and...
27
by: Greg Smith | last post by:
Hello, I have been given a programming task that falls into the "impossible" category with my current skill set. I am hoping somebody out there knows how to do this and can save my b-t. I...
0
by: Gianluca | last post by:
Is is true that it's impossible to write a C# wrapper for an IDispatch COM object that has more than one property with parameters? I tried everything I could think of and nothing works. You can...
2
by: Michael B. | last post by:
Hi! I have a very simple question: Is it still true that pre variable incrementation (like ++i) is faster than post incrementation (i++). I heard that in modern compilers it makes no difference...
2
by: Cat | last post by:
I created a web site, and I thought I followed XHTML 1.1 rules. But when I validated the pages, I got some error messages. I found that those codes are automatically generated parts by ASP.NET. ...
9
by: Gabriel | last post by:
Hello, I installed SQL server 2005 SP1 on a Windows XP SP2 From Visual Studio, I'm trygin to create a connection to a database, but I receive this error but I'm creating the connection (I...
4
by: sam | last post by:
hI, I am little confused here See i have int wordlen=10; when int s is array s++; whats the meaning of this
2
by: sanctus | last post by:
what is the difference between for(j=0;j<cl.ts->size();++j){ double l=cmbcalc->j2l; } and
6
Dormilich
by: Dormilich | last post by:
Hi, I’ve got a mathematical script, which is currently running fine*, although it bothers me that JS does not always increment correctly. sometimes it happens that the incremented value is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.