473,945 Members | 7,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Incrementation impossible?

2 New Member
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 1723
Ganon11
3,652 Recognized Expert Specialist
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
Prometheum
2 New Member
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 Recognized Expert Specialist
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
1456
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 getY() of the class Animale from the class Leone, the compiler return to me the same errors. These are the errors: c:\Documents and Settings\Angelo\Documenti\Visual Studio Projects\Savana\Leone.cpp(36) : error C2248: "Animale::x": impossible to...
27
1940
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 work for a large University. I wrote a Windows-based database application for my department that is used in purchasing. The University has just released Web-base application that does the same thing using a sub set of the data that my application...
0
1054
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 only use the this indexer for one parametrized parameter. If this is true, anyone knows if this limitation has been lifted in 2.0? It also appears to be a bug in the proxy that marshals calls to the COM interface is unable to call...
2
3898
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 as the both versions are optimised to one type of code. I've also never encountered any performance difference in using e.g. for(i=0; i < n; ++i) statement;
2
1204
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. There is no attribute "name". <form name="form1" method="post" action="Default.aspx" id="form1"> And input is not allowed here Since ASP.NET buttons should be placed in server side forms, I don't know how to remove this error. So, what this...
9
2630
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 don't receive the database list in the dropdown) "An error has occured while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that
4
1895
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
1366
by: sanctus | last post by:
what is the difference between for(j=0;j<cl.ts->size();++j){ double l=cmbcalc->j2l; } and
6
2165
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 slightly bigger/smaller (around the 12th decimal place) than it should be (I’m usually incrementing by 0.1). because of that it affects the accuracy of the results. incrementation: - Fn.search() line 239 & 248 value assignment: - Fn() line 83-85 ...
0
9974
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11140
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10679
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7402
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3523
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.