how can i compare the a private variable of a class and a value in the column of a text file.
there is a syntax error in my code while comparing. senario is i am getting bus details like busno, source , destination,typ e of bus, price/head . I should compare the busno which i get through object to the bus no which is present in a .txt file. and contents in the text file is as the format below.
|1488|xxx|uuuu| A/c|150.
|1422|mmm|oooo| nonA/C|900.
Aug 8 '08
13 2615
Please read our posting guidelines taking note of the sections on choosing a thread title and composing your post (using code tags round the posted code).
You have posted code and said you have a syntax error, this is not enough you should post the exact error you are getting (copy and past it) and you need to tell us on what line of code it is appearing.
However in general
1. You have declared main as returning void. This invokes undefined behaviour, all bets are now off your program could do anything. Examining any further errors after this one is pointless.
Main MUST be declared as either
int main()
or
int main(int argc, char **argp)
that is it must return int.
2. Private data is only accessible inside the class. I don't see you calling any class methods so I assume your syntax error is attempting to access private data. You will need to provide access to the data by either creating a method to return the data, creating a method to do the comparison for you, changing the access specifier of the data being declared (but not this last one is really a hack).
yeah
i have did but again error.
declared a function to get bus no
public:
void get_bus_no()
{
cout<<bus_no;
}
while getting the bus_no i used a temporary variable busno converting it into string , assignin it to bus_no and declared bus_no as string in private.
cout<<"Enter Bus_No::";
cin>>busno;
bus_no=string(b usno);
i have declared bus_no as private.
private:
string bus_no;
but still error in this line
if(strcmp(strin g(obj2[n].get_bus_no()), obj.get_bus_no( ))==0)
Banfa 9,065
Recognized Expert Moderator Expert
declared a function to get bus no
public:
void get_bus_no()
{
cout<<bus_no;
}
This doesn't get the bus number it prints it to the console!
if(strcmp(strin g(obj2[n].get_bus_no()), obj.get_bus_no( ))==0)
What type is strcmp expecting for the parameters being passed to it? What type is get_bus_no() returning? Are these types compatible?
Savage 1,764
Recognized Expert Top Contributor
Again,your function is of void type and void functions can't return any value.What you did is just printed the value of bus_no to the screen,but you need to return that value to the calling function.So declare your get_busno() function to return the same type of which is bus_no made.
EDIT:Also bus_no is a int,but it's the string you need to return.
yeah
if(strcmp(strin g(obj2[n].get_bus_no()), obj.get_bus_no( ))==0)
When you declare your get_bus_no() method so: - std::string& get_bus_no() const {
-
return bus_no;
-
}
-
Then you do not need strcmp anymore. The strcmp function is only used for comparing char*. You can find out all about standard library strings and string comparison / manipulation on the internet.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: richardkreidl |
last post by:
I have the following hash script that I use to compare two text files.
'Class
Public Class FileComparison
Public Class FileComparisonException
Public Enum ExceptionType
U 'Unknown
A 'Add
D 'Delete
|
by: martin1 |
last post by:
I just use DataSet to bind DataSetGrid and display from SQL DB.
when starting run in Visual Studio 2005, get "Line 1: Incorrect syntax near
'1'" error message from below fill line,
objDataAdapter.Fill(objDataSet, "mindata")
any help is greatly appriciated.
|
by: BenCoo |
last post by:
Hello,
In a Binary Search Tree I get the error : Object must be of type String
if I run the form only with the "Dim bstLidnummer As New BinarySearchTree"
it works fine.
Thanks for any help on this,
Benny
|
by: W Karas |
last post by:
Would the fear factor for concepts be slightly reduced if,
instead of:
concept C<typename T>
{
typename T::S;
int T::mem();
int nonmem();
};
|
by: Superman859 |
last post by:
Hello everyone. Heads up - c++ syntax is killing me. I do quite well
in creating a Java program with very few syntax errors, but I get them
all over the place in c++. The smallest little things get me, which
brings me to...
I'm trying to create a program that gets a string from standard input
and then manipulates it a little bit. It has to be a char array and
not use string from the library.
Here are my prototypes:
| |
by: Travis |
last post by:
I'm creating a real simple tree. No sorting and every node can have
infinite children.
// TreeNode.h
#ifndef TREENODE_H
#define TREENODE_H
#include <iostream>
#include <iomanip>
|
by: Frogpolish |
last post by:
well after searching ans coming up with nothing i figured id post something in here to see if i could get some help. i have an access db that keeps track of flights that ive flown. its a logbook basically. now im writing a program to add to that database and for some reason it keeps giving me "Syntax error in INSERT INTO statement" when it comes to the dataadapter.update method. here is the code, i will also include a link to the code with all...
|
by: Banfa |
last post by:
So I have a little problem, I have a template class and that class contains a template function; now what I want to do is declare that function in the class (or indeed the entire class) as a friend of all specialisations of the class.
I did that (or thought I did) but the code I produced compiles with gcc 3.4.2 but not with Microsoft Visual Studio 2008 (Express Edition). So I have reduced my code to a minimum compilable example that exhibits...
|
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...
|
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,...
|
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...
| |
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |