473,566 Members | 3,309 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 2125
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
1964
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 = classmethod(foo)" mechanism custom printing for class objects is not possible. #!/usr/bin/python class Foo:
8
2568
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
1799
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 application. So when the Application starts I read the xml file and place each key-value pair into a Synchronized hash table. Now I want to save this...
15
4733
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 button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is...
5
6899
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
2
2514
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 is the usage of "Custom Attribute" in real life project. Can somebody please help me understand where are these informations really helpful in...
0
2020
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 this topic getting lost before people interested in the problem notice it. The important tricks to the solution are two: 1) make the custom classes...
1
2126
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 input or return) custom classes' objects e.g. userinfo, customerinfo etc. When i generate the proxy classes for these services using wsdl, the...
10
2640
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 namespace file so I can import them in the webpage. Can someone clarify? Thanks.
0
2614
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 multitude of web methods. All the web methods have various parameters, but one parameter which they all have in common is an 'object' parameter. This...
0
7584
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...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
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...
0
7953
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...
1
5485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
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...

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.