473,402 Members | 2,055 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,402 software developers and data experts.

Problem in comparing string of integers.

Is there any function which can compare first size and then inner elements.. I have used compare functions but that outputs the same.
Expand|Select|Wrap|Line Numbers
  1. string A="100001",B="9";
  2.  
  3.      if (A>B)
  4.      {
  5.          cout<<" ***A****";
  6.      }
  7.      else if (B>A)
  8.      {
  9.          cout<<"   *****B*****";
  10.      }
  11.      else if (B==A)
  12.      {
  13.          cout<<"*******same******* ";
  14.      }
  15.  
Thankyou!
Feb 27 '16 #1

✓ answered by AceInfinity

You'll have to convert the strings to integers to use those operators, or overload the operators for the strings which will do the conversion or calculate the numbers based on the characters yourself.

3 1385
Unless the > and == operators are overloaded, what exactly do you expect them to do? They are strings. What would you expect "Cat" < "Dog" to evaluate to? They are only defined for numeric value types mainly.
Feb 28 '16 #2
Well I have used another method. And the thing which I was asking was that it is giving 9 > 10001 . which is not the desired result.

Thank You!
Feb 28 '16 #3
You'll have to convert the strings to integers to use those operators, or overload the operators for the strings which will do the conversion or calculate the numbers based on the characters yourself.
Feb 28 '16 #4

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

Similar topics

5
by: Blue Ocean | last post by:
In short, it's not working right for me. In long: The program is designed to read numbers from an accumulator and speak them out loud. Unfortunately, the class that contains the method to...
12
by: Elijah Bailey | last post by:
I have two char arrays of size k. I want to know which one is bigger (exactly like for instance I compare two ints/longs/etc.). What is the fastest way to do this? k <= 10 usually for my...
3
by: Robert Dell | last post by:
I have a problem comparing strings in an order form i'm writing. I want to give a running total at the bottom of the page and it appears to be working except it doesn't compare correctly (it...
4
by: - Steve - | last post by:
The following line of vb.net code works fine: if(strAnswer.toUpper() = strUserAnswer.toUpper()) However in an ASP.net page I'm told Object reference not set to an instance of an object ...
3
by: Rich | last post by:
Hello, I am converting an app from VB6 to VB.Net and have encountered the following problem. I have the following loop which retrieves objects from a collection of objects. Dim entry As...
3
by: Irfan | last post by:
hi, I have a fileName stored as a string as shown: String fn = @"C:\drawing\testdrawings\test; which gives fn = "C:\\drawing\\testdrawings\\test; however i dont want '\' to get converted to...
4
by: MBeckford05 | last post by:
Hello, I am trying to write java program to input three integer numbers compare them and display the largest and Smallest number. I have thought about the problem I would need to use a comparison...
4
by: MC felon | last post by:
what's the best way to compare two string elements? std::string cstr; if ( cstr.at(3) == cstr.at(2)) //do something or std::string cstr; if ( cstr == cstr) //do something ?
3
by: KusoYumi | last post by:
Hello, im facing a problem on String and String. I pass a value from another jsp , and i get the value at backend. Then i need to set this value into String which index 11 and pass back to jsp and...
6
by: sabel | last post by:
Hi I am a problem comparing DDC AND "DDC" , the if statement is not working. here is my javascript code var DDC=document.getElementById("<%= hvalue.ClientID %>").value; ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.