C++ ::  Type Conversion Cannot Guarantee Value Preserving?

Feb 13, 2014

I did an interesting test on the type conversion between int and unsigned long. the results is like the following:

#include <iostream>
#include <limits>
using namespace std;

int main() {
int ival(-100);
unsigned long ulval1(numeric_limits<unsigned long>::max());
unsigned long ulval2(10);

[Code] ....

18446744073709551615
8
18446744073709551515
8
18446744073709551526

what I want to say is, there can be several conditions for adding a signed int to an unsigned long:

1: if the ival is positive, then adding a positive to a positive, both value should be converted to unsigned long, which is reasonable, even when the sum is larger than the max limit of unsigned long, because user himself should be ware of that the sum value may be too large and will be modulo into the range of unsigned long.

2: if the ival is negative, but the sum is positive, then both sum and ulval can fit in unsigned long, so we should convert them into unsigned long

3: if the ival is negative, and the sum is also negative, that means the ulval's real value can actually fit in int range, so the compiler should convert it to int, so as to preserve the value. but compiler didn;t do this to comply it's "preserving value" rule.

View 3 Replies


ADVERTISEMENT

C++ :: Threads Giving Error - Call Of Object Of A Class Type Without Appropriate Operator Or Conversion

Jan 27, 2015

I made a simple binary tree then decide to try out threads too. I got the following error:

call of an object of a class type without appropriate operator or conversion

Code:
#include "Tree.h"
#include <iostream>
#include <thread>
void main(void){

[Code] ....

I am having a hard time figuring out why the error exists. I tried adding the new operator but that did not work.

View 11 Replies View Related

C++ :: Type Conversion - Float Or Double Variable Into Unsigned Char Variable And Back

May 10, 2013

I would like to convert a float or double variable into unsigned char variable and back.

float number_float = 23.453f;
unsigned char* number_char = (unsigned char*)malloc(sizeof(float));
number_char = reinterpret_cast<unsigned char*> (&number_float);
float* number_float_0 = reinterpret_cast<float*>(&number_char);

I am not getting the same value back.. why?

View 2 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++ :: Zip To City Conversion

Apr 9, 2014

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int displayMenu ();
void addRecords ();
void zip ();
void city ();

[Code] ...

View 11 Replies View Related

C/C++ :: Time Conversion Between EST And UTC

Apr 1, 2013

I want to convert time from est to utc. Is there any function for this.

View 3 Replies View Related

C++ :: 32 / 64 / 80 Bit Float Conversion?

Feb 14, 2012

I am looking for a math/big num library, that allows me to convert 32/64/80 bot float numbers to string and vice versa.

Precision & accuracy is of importance here, and since this is an IEEE standard, i have high hopes that there are libraries for this out there, which would save me the hassle of trying to implement this myself...

View 1 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 :: Lowercase / Uppercase Conversion

Oct 15, 2014

I am having trouble in creating a program (named "up.c") that should do the following:

- if you run the command ("up") with no arguments, it should read input from stdin and display it on stdout, converting lowercase letters to uppercase.

- if you run the command with one or more files (as arguments to the "up" command), your program should read input from each file and display it on stdout, again converting lowercase letters to uppercase.

I'm trying to create a single program that can do both of these, and handle errors gracefully. I've found that some codes work to convert the letters, but they seem overly simple and aren't giving me what I'm looking for in my program.

View 2 Replies View Related

C :: Float / Integer Conversion

Oct 14, 2013

why does the following code output "0.000000" instead of "1.000000"?

Code:

#include <stdio.h>
int main(void) {
int x=3, y=2;
printf("3/2 is %f
", x/y);
return 0;
}

the code was compiled and run using gcc 4.4.7 and glibc 2.17 on linux kernal 2.6.32 running on a PC with an intel i5-2500k cpu(sandy bridge)

View 8 Replies View Related

C++ :: Conversion From PDF To Text File

Feb 25, 2013

I have this project, How do I ever Convert a .Pdf file to .txt file using C++.

View 5 Replies View Related

C/C++ :: Number Conversion To String

May 22, 2014

I'm writing a small pice of code that takes numbers and convert it to string. So that's what I got

int main() {
char letter;
char letter1;
char letter2;
cin >> letter;
cin >>letter1;
int sum = letter * 128 + letter1;

[Code] ....

Then it asks the user to enter a letter, say 'w' , which it's value is 119

Then enter another letter, say 'o' which value is 111

then it do the equation, which is take the value of the first letter multiple it by 128 then add it to the value of the second letter.

How can I make it does this process in a For loop, or any kind of loop??

Then I have the second part which is the other way around. That is when the user enter a numbers then the code convert these numbers to a string.

251394404 - "d"
1964018 - "rd"
15343 - "ord"
119 - "word"

so what's happening here is the it divide each time by 128. But I can't do that in a code.

View 3 Replies View Related

C++ :: Conversion Between Char And String

Jun 7, 2013

I have a question on conversion between char & string. I have cut & pasted the part of the code from my C++ code and my function "decryptPwd" uses C style code with "char" etc.

I need to pass a string (mypwd) somehow to this function after conversion & then compare it to another string (newmypwd).

I tried - "decryptPwd(mypwd.c_str())==newmypwd.c_str()" but it did not work.

..
#include <string>
..
char* decryptPwd(char hash[64]);
main () {
string mypwd;
string newmypwd;
if (decryptPwd(mypwd)==newmypwd)

[Code] ...

View 7 Replies View Related

C/C++ :: IP Address To Binary Conversion

Mar 10, 2014

Converting an IP address to a binary number? As in the entire thing 123.45.555.49 to it's binary equivalent.

View 14 Replies View Related

C# :: SQL Insert DateTime Conversion

Sep 12, 2014

I am trying to insert values from a form into my SQL database. Two of the fields in the SQL database are of type DateTime.

When trying to insert I am receiving the error "Conversion failed when converting date and/or time from character string."

The relevant code is as follows:

DateTime saveNow = DateTime.Now;
string sqlFormattedDate = saveNow.ToString("yyyy-MM-dd HH:mm:ss");
conn.Open();

[Code] ....

The table layout:

View 5 Replies View Related

C Sharp :: Conversion Table From CSV To XML

Jul 9, 2012

I am beginner in developing C # and I will like to develop an application that a converte. csv file (table) in an xml file

View 1 Replies View Related

C++ :: 2 Argument Conversion Function

Nov 26, 2012

i have used single argument conversion function which gets called in below scenario.

Code:
#include<iostream>
using namespace std;
class Demo
{

[Code]....

It is giving error "test3.cpp: In function `int main()':test3.cpp:18: syntax error before numeric constant"

But it should work as Demo d=100; works

View 3 Replies View Related

Visual C++ :: OBJ Conversion - XML Structure

Jun 14, 2013

I'm trying to make OBJ converter. The file structure of which I am trying to convert is an XML structure. Here's an example. I currently have a lua script that does this for me. But it always crashes on big objects. It's for a game called "ROBLOX" The only information I need to convert is.

<int name="BrickColor">194</int> <-- Brick Color
<CoordinateFrame name="CFrame"> <-- Position
<X>0</X>
<Y>0.600000024</Y>
<Z>0</Z>

And

Vector3 name="size"> <-- Part size.
X>1000</X>
Y>1.20000005</Y>
Z>1000</Z>

Here's the lua script. [URL] .....

This currently grabs all of the ClassNames in the place and converts them to OBJ wavefront gemotry.

View 3 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++ :: Binary To Decimal Conversion Program

Jul 25, 2013

So I tried debugging this program almost 10 times, each time finding a problem then making code to fix it, I used to get wrong values but then now after I changed the calculation from an infinity while loop to a for loop (because after some changes I realized that now I know the number of entries, meaning the start and the end of the loop) the program now displays no values at all. I checked it thoroughly and until the calculation process its functioning exactly the way it should but then the calculation breaks hell loose . Also the for loop that raises 2 to the power needed works fine too so it must be something with the other processes included in the calculation....

This used to be a function of a multiple value types conversion program, I isolated it for easier analysis as a lone standing program.

Code:
#include<iostream>
using namespace std;
int main() {
int d[10],e[10],anse=1,r,limit;
short int counterd=0,i,j;
float bind=0;

[Code] ....

View 11 Replies View Related

C++ :: Infix To Postfix Using Stack Conversion

Mar 8, 2013

I am Getting following errors I don't know why.I have mentioned the lines (in comments) where these errors are occurring.
__________________________________________________
warning C4018: '<' : signed/unsigned mismatch
error C2064: term does not evaluate to a function taking 0 arguments
error C2064: term does not evaluate to a function taking 0 arguments
__________________________________________________ _

Code:
/////////////////////////////////////////////////
//libraries
/////////////////////////////////////////////////
#include <iostream>
#include <string>
using namespace std;

[Code] .....

View 1 Replies View Related

C :: Currency Conversion Control Module

Nov 3, 2013

Code:
/*Currency Conv Control Module*/
#include <stdio.h>
#include "currencyconv.h" /* defines constants, declares functions */
int main(void) {

float us_dollars;
float currency;
int user_input;

[Code] ....

This is $$ converter program I created that is split up over 3 files. It takes the users input in US Dollars and converts it to the currency selected. When executing the program I am encountering a small problem. It actually isn't converting anything and returns 0.00 dollars.

I would like for it to convert the amount entered into the currency selected. I would also like to add in the print statement the type of currency the user has selected.

View 3 Replies View Related

C :: Stack Conversion From Infix To Prefix

Sep 16, 2013

Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#define MAX 50

[Code] ....

[URL] .....

My output should look like this ..

Enter an expression in infix form: (9+6)/(2*4)^15

Specify output expression type,1) Prefix 2)Postfix
The Prefix expression is: /+96^*2415
----------------------------------------------
Enter an expression in infix form: (9+6)/(2*4)^15

Specify output expression type,1) Prefix 2)Postfix
The Postfix expression is:96+24*15^/

View 2 Replies View Related

C :: Currency Conversion Update From Internet

Jun 15, 2013

i have given a project for currency conversion program with add,delete,search,display option. but i was thinking if it can update the currency rate from internet at beginning.

View 3 Replies View Related







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