C++ :: How To Compare Two Variables Who Do Not Have A Predefined Type

Feb 3, 2013

How do I compare two variables who do not have a predefined Type (i.e Templates).

If I just do a==b it only works for integers and not for strings. Is there any general method present for comparing templates.

View 6 Replies


ADVERTISEMENT

C :: Pull System Information And Compare Results With Predefined List

Feb 9, 2014

How to pull system information and compare it's results with a predefined list.

I know the second part, how to pull system information. Like what CPU/GPU/Motherboard the system that the program is run on has.

View 11 Replies View Related

C++ :: Read Function - Compare And Assign Variables

Mar 1, 2013

I am developing a program that will read a function (x^2+2x+4 or other function) and then comparing and start assigning variables. My idea is with an array:

int i,x;
char xs;
char function[20];
cin.getline(function, 20);
cout << "Your function is: ";

[Code] .....

Well this is my basically idea, but when the program detect an ^ this will be associate with the exp(x,n); well in general the user enter a function: x^3+3x^2+4x-8 give a value for x for example 3 and the program will convert in -- exp(3,3)+3*exp(3,2)+4*3-8 --, but I don't know how.

View 2 Replies View Related

C++ :: Compare String Vector Against Enumerated Type?

Jun 26, 2014

How do I compare a string vector against an enumerated type? My code so far is:

void convertToLastFirst(vector<string>&names){
enum NameFormat{FIRST, LAST};
for (size_t i = 0; i < names.size(); i ++){
if (names[i] FIRST){
names[i] = LAST;
}
}
}

View 1 Replies View Related

C++ :: Returning Variables As Char Type With If Statement

Feb 17, 2014

Ive been getting an odd error with this code when I try to compile it, as well as Im not quite sure as how to return my variable "compType" as a char type.

Main
#include <iostream>
#include "Shape.h"
#include <iomanip>
#include <cmath>

using namespace std;
void inputShape( char shape)

[Code] ....

View 1 Replies View Related

C/C++ :: Use Modulus Operator With Double Type Variables?

Mar 13, 2013

how can we use modulus operator with double type variables

View 2 Replies View Related

C :: Pointer To N-dimensional Array That Has A Predefined Shape

Feb 12, 2013

dynamically allocated arrays. int (*ttt)[2][10]; If I'm not mistaken this declares a pointer (that's all). This pointer has an intrinsic shape that makes it easier to access row, column without doing my own math to calculate the offset.

ttt = malloc(2 * 10 * sizeof(int));

So I should be able to access elements like this: ttt[i][j].

ttt[i][j] = 123;

But the compiler says: error C2440: '=' : cannot convert from 'int' to 'int [10]'...how to go about accessing a monolithic block of allocated memory using 2 or more dimensions, using some sort of casting to a known shaped array if possible. As opposed to doing i * cols + j type stuff.

View 2 Replies View Related

C++ :: Fastest Comparison Algorithm Based On A Predefined Container?

Sep 3, 2014

Suppose you have defined a container of elements and you want do define a comparison function between elements based on the ordering of the elements in that container. What algorithm for the comparison would be the most efficient?

Example:
master = {tom, sam, mary, sally, bert, frank}
subset = {bert, sam, mary, tom}
goal: change subset to {tom, sam, mary, bert}

My current idea is to simply iterate from the beginning of the container, and whichever of the two elements is found first is the lesser (assuming the second is not the same as the first). It seems kind of naïve though. Any better performing algorithm? This is what I have so far:

#include <iostream>
#include <iterator>
#include <list>
#include <vector>
#include <stdexcept>
#include <algorithm>

[code]....

Would perhaps forcing the container to have a random access iterator, like vector, and then writing a specialized comparison function based on that perform even faster? Or perhaps force the container to be a map to integers, and compare the elements by comparing the integer mapped values?

View 19 Replies View Related

C# :: Unable To Implicit Convert Type Int To String Though Declared Variables As String

Mar 26, 2014

Ok, so I'm writing this code and when I build it keeps saying cannot implicitely convert type int to string even though I declared my variables as string. Why is it giving me this error?

private static string Repair()
{
string result="";
string beep;
string spin;
Console.WriteLine("Does your computer beep on startup?:(y,n)");

[Code]...

View 3 Replies View Related

C++ :: Changing Array Of Numbers Of Type Char To Type Int?

Apr 27, 2013

I'm having some problems with changing an array of numbers of type char to type int. Every time i try to sum 2 array indexed values it returns some letter or symbol. Also, if i change the type of the array in the functions the compiler gives me an error message. I would also like to add that the problem requires that the first two arrays be char so each individual number gets assigned to a different value.

My current code is:

Code:
#include <iostream>
void input(char a[], char b[], int& size_a, int& size_b);
void convert(char a[], int size);
void reverse(char a[], int size);
void add(char a[], char b[], int c[], int size);
int main()

[Code]....

View 4 Replies View Related

C++ :: Convert Element Of Int Type Of Array To Char Type?

Dec 21, 2013

how to convert an element of int type of an array to char type?

View 2 Replies View Related

C++ :: Determine If Type Is Of More Derived Type Than Another At Runtime

Aug 31, 2014

I have a function like this:

template<typename T>
void f() {
//...

[Code]....

list contains, in order: A, B and C in any order, D, E

I am thinking it is possible with some clever template and polymorphism combos, but maybe not. As a last resort I know how to make it work by storing static type information in each class, but I'd like to avoid that if possible.

View 6 Replies View Related

C++ :: How To Use Type RectangleF As Built In Type

Jul 22, 2013

I need to use the type RectangleF as a built in type in c++ ie I need to declare a variable rect as RectangleF rect;

what do I have to include to be able to do this.

View 2 Replies View Related

C++ :: Declare Template Type Object Inside Template Type Class Definition

Oct 12, 2013

Let me put it into the code snippet:

/**
This class build the singleton design pattern.
Here you have full control over construction and deconstruction of the object.
*/
template<class T>
class Singleton

[Code]....

I am getting error at the assertion points when i call to the class as follows:

osgOpenCL::Context *cxt = osgOpenCL::Singleton<osgOpenCL::Context>::getPtr();

I tried commenting assertion statements and then the debugger just exits at the point where getPtr() is called.

View 7 Replies View Related

C :: Can't Compare 8 Bit Value With 16 Bit Value

Jun 24, 2014

Apart from compiling i am running a software to test for compliance with standards. I always get the following warnings.Implicit binary conversion from one (type) to (type). The type in general can be unsinged int, long etc. There are several cases in which this happens. Like in an if statements, i made sure that both the types are of the same type by type casting.Is it true that i cannot compare an 8 bit value with 16 bit value? I cannot compare a signed value with an unsigned value?what are the exact rules for this?

In an assignment operator i cannot assign a bigger value to the smaller value. Am i correct?Suppose if i multiply a varaible with constant then the constant should be type casted to the same value as the variable?Also if i am shifting a variable say test1 << 1. Then should 1 also need to be typecasted. How to handle situations if the variable is a complex structure or union? i am very much cofused not able to follow definite rules and mostly trying trial and error and i dont want to do that way.

View 5 Replies View Related

C++ :: STL Map Compare Operator

Jun 13, 2012

In stl map, if I insert two keys, say a and b. It looks like compare operator is called twice. First time a<b is called and second time b<a is called. Why are both a<b and b<a called?

View 6 Replies View Related

C++ :: Compare Two Strings Of Numbers

Jan 4, 2014

I am trying to figure out how to go about comparing two strings of numbers. I have two files that both contain numbers 1-50, one file has multiple repeating numbers while the other one just has 1-50.

I want to compare the files and count how many of each number a occurred and make a chart with * next to the number. First I figured I would use the strings like an array and compare them using nested loops. Then I noticed I have single and double digit numbers. The numbers in the files are printed as:

1 44 5 34 4
2 22 7 55 4
...... etc

Compared too:
1
2
3
4
5
......
50

I thought about using string stream and converting the string to int but wouldn't it just be a huge number when set to the int variable? Then I thought about a array initialized with 1-50 and compared to the file but I still have the issue with single and double digit numbers.

My question is how can I just read one number at a time, either double or single digit?

View 11 Replies View Related

C++ :: How To Compare Two Double Values

Mar 24, 2014

I want to compare two double values

double x = 3072.00000000;
double y = 3072.0000000;

when checking with if its not working

if(x==y) it not working

View 1 Replies View Related

C++ :: Compare Function On Sets

Oct 18, 2014

How can I declare a set of strings that i want to be ordered by a boolean function Comp? Like the one you would write in

sort(v.begin(), v.end(), comp);

I tried
set<string, Comp> S;
but it doesn't work

And the same question for priority queues, can you specify the function you want your elements to be sorted by?

View 4 Replies View Related

C++ :: How To Compare Similarity Of Two Vectors

Mar 8, 2013

This is possibly more of an algorithm question rather than c++ related.Suppose I have two vectors:

std::vector<double> first = {1.0,2.01,3.05,4.05};
std::vector<double> second = {1,2,3,3,4}; // very similar except no decimals and a second "3"

And now I want an algorithm that will tell me how similar these two vectors are. That is, I want to know how much of first is similar to second.

View 6 Replies View Related

C++ :: Compare Any Two Numbers Input

Jan 11, 2015

Program is about to compare any two numbers input. Then, it will display whether the number is minimum or maximum. Use switch statement.

#include <iostream>
using namespace std;
void main() {
int num1, num2;

cout << "Input 2 integers separated by a space. " << endl;
cin >> num1 >> num2;

[Code] .....

View 4 Replies View Related

C++ :: OOP Compare Member Function

Feb 10, 2015

I have an assignment in my OOP c++ class and I had to create a class called date and one of the member functions is a compare function that compares two dates that are taken in. It is suppose to be something like this:

Date d1(12,25,2003);// Dec 25, 2003
Date d2(5,18,2002);// May 18, 2002

d1.Compare(d2);// returns 1 (since d2 comes first)
d2.Compare(d1);// returns -1 (calling object is d2, comes first)

Then if d1 and d2 are equal then it returns 0.

This is what he gave us to start with the function:

int Date::Compare(const Date& d) {
}

View 11 Replies View Related

C++ :: Compare Value In Switch Statement?

Sep 23, 2013

is it possible to compare value in switch statement? i.e: a > b

View 5 Replies View Related

C++ :: Can't Compare Char Strings

Jun 13, 2013

I have two char* that have the same data in (hypothetically).

std::vector<char*> Buff;
Buff = Split(Line, '.');
char* A = "data", B;
B = Buff.at(0)

Where Split is a function that I made to split a string (Line in this case) into a char* vector, this string contains a line from a file. Line is char* too. The weird problem is when Buff data stored in its 0 position is given to B... because B is equal to A (hypothetically) but when this is compared to do certain functions they doesn't match!

Here an example:

std::vector<char*> Buff;
Buff = Split(Line, '.');
char* A = "map", B;
B = Buff.at(0) // Buff.at(0) should be "map" and is apparently "map"

[Code].....

NOTE: I didn't use switch to compare Cmd because I want it separately for easier debugging.

Is there something wrong with my codes?? or what happened here with those hex values before the string in my variables?

View 6 Replies View Related

C# :: Compare Tree Views?

Aug 7, 2014

I have two Tree views populated from XML files. I have them loaded side by side in a windows form. treeView1 and treeView2. I need to compare these two treeviews and highlight any difference in any of the nodes. I am using C#.NET Visual Studio 2012 professional.

treeView1
BIOS_DETAILS
-Manufacturer
-- Hewlett Packard

[Code].....

I need to compare these and highlight the differences in color.

View 14 Replies View Related

C++ :: How To Compare Two Histograms Using Opencv

Mar 6, 2013

I am tying to compare two histograms, but it gives error. Here I have given my code, histogram file and error message. Histogram file 3*5 matrix(output_test.txt):

1 2 3 4 5
5 2 1 4 2
2 1 2 4 2

code:

int main(..........)
{ ................................................
Mat first_histogram(1,feature_vector_size, CV_32F);
Mat second_histogram(1,feature_vector_size, CV_32F);
for(i=0;i<count_row;i++)
{
for(j=0;j<count_row;j++)
{

[Code]...

Error message: error LNK2019: unresolved external symbol "double __cdecl cv::compareHist(class cv::Mat const &,class cv::Mat const &,int)" (?compareHist@cv@@YANABVMat@1@0H@Z)

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved