473,499 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using custom classes

2 New Member
I'm using the code below and I keep getting issues with using strings and the custom class Menu. Any help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. /*Andrew Smith
  2.  *ajs0025
  3.  *Menu.cpp
  4.  */
  5. #include <iostream>
  6. #include <vector>
  7. #include <string>
  8.  
  9.  
  10. using namespace std;
  11.  
  12. //modified from your example menu class.
  13. class Menu
  14. {
  15. public:
  16. void printOptions( vector<string> options )
  17. {
  18.     for(int i=0;i < options.size(); i++)
  19.     {
  20.     string option = options.at(i);
  21.     cout<< option << endl;
  22.     }    
  23. }
  24.  
  25. void addOption( string newOption, vector<string> options){
  26.     int j = options.size();
  27.     j++;
  28.     options.push_back (newOption);
  29. }
  30.  
  31. //modified from your example "http://www.eng.auburn.edu/~xqin/courses/comp2710/getnumber.cpp"
  32. int getNumber ( int& choice )
  33. {
  34.   while ( !( cin >> choice ) ) {
  35.     if ( cin.eof() )
  36.       return 0;
  37.     else {
  38.       char ch;
  39.       cin.clear();
  40.       cout<<"Invalid input, please try again: ";
  41.       while (cin.get(ch) && ch != '\n' );
  42.     }
  43.   }
  44.  
  45.   return choice;
  46. }
  47.  
  48. private:
  49. vector<string> options;
  50.  
  51.  
  52. };
  53.  
  54.  
  55.  
  56. class main
  57.  
  58. {
  59.  
  60.     Menu test;
  61.  
  62.     string testString; 
  63.     testString = "this is a test";
  64.  
  65.     test.addOption(testString);
  66.  
  67.     test.printOptions();
  68.  
  69.  
  70.  
  71. };    
  72.  
  73.  
Feb 18 '10 #1
2 2124
Banfa
9,065 Recognized Expert Moderator Expert
What issues? Please describe your problem properly and fully.
Feb 18 '10 #2
s0lidjacks0n
2 New Member
Sorry, I figured it out.
it had to do with the fact that I had declared main a class rather than a function, because I'm a moron.
Feb 18 '10 #3

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

Similar topics

3
1956
by: Neil Zanella | last post by:
Hello, In Python, classes are objects. But there is no way to custom print a class object. This would require some syntax such as the one commented out below: With the current "foo =...
8
2558
by: FS Liu | last post by:
Hi, I am writing ATL Service application (XML Web service) in VS.NET C++. Are there any sample programs that accept XML as input and XML as output in the web service? Thank you very much.
0
1789
by: Brett | last post by:
I am working with vb.net in a asp.net application. I have created a config file in xml format. The goal is to be able to change the config file without having to recompile the entire...
15
4712
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
5
6890
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
2
2507
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article...
0
2014
by: ivan.leben | last post by:
I am writing this in a new thread to alert that I found a solution to the problem mentioned here: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/7970afaa089fd5b8 and to avoid...
1
2123
by: Ankur Goenka | last post by:
Hi, I am trying to include two proxy classes (from two different web services say Namespace.Service1 and Namespace.Service2) in a project (C# Class lib). These webservice internally use (as...
10
2633
by: cykill | last post by:
Hi. I'm new to asp.net and I've been searching on the net and in book on how to use custom namespace. I've created my own custom namespace and I just need a straight answer on where to put the...
0
2607
by: jb489 | last post by:
Hi all, Hope I am posting this in the right forum. I seem to be having a problem when using serialization and web services. <b>Scenario:</b> I have built a web service which includes a...
0
7009
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
7178
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
7390
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...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4602
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...
0
3103
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...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
302
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...

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.