Programming :: Ostream<< Operator With Double Variable Is Not Accurate?

Mar 27, 2010

I have tryed out this operator on program:

Code:

#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
ofstream myfile;

[code]...

which definitly is not the same number. I guess somewhere in the convertion from double to char* ("<<") something is not right and what can i do to save these double numbers in an accurate manner in a file?

View 14 Replies


ADVERTISEMENT

Programming :: C++ Operator Overloading Within Already Overloaded Operator

Apr 16, 2011

I'm having a bit of an issue using overloaded operators in an already overloaded operator. In my following code, I have overloaded the && operator to compare two Course objects. The operator in turn goes to a function which calls other overloaded operators to compare private object variables of that object to compare them.

View 8 Replies View Related

Programming :: Can't Get The OR Operator To Work?

Apr 18, 2011

I'm having a bit of trouble getting the OR operator to work.This is the code that I have:

global.php:
Code:
$vars["admin link"] = "<a href='/path/to/admin.php'>Admin</a>";
$vars["admin ip"] = "xxx.xxx.xxx.xx1";
$vars["admin ip2"] = "xxx.xxx.xxx.xx2";

[Code]...

View 7 Replies View Related

Programming :: TCL AND Operator (&) On A Binary Value?

May 1, 2010

I have a binary value which I receive from a controller. Say this binary value is 42. Just plain hex 42. If you would look at that byte in a debugger you would see 42.Now this value hold 8 bits each indicating a high or a low output. So 0x42 = 01000010b. Which means bits 1 and 6 are '1'.When I would want to find out which bits are set and which are not in a language like C, I simply do:

Code:

mask = 0x80;
if (binval & mask) {...}
etc..

However I am programming in TCL, and I try to do:

Code:

set mask 0x80
if { [expr ($binval & $mask) > 0] } {...}
etc...

this fails. At the moment the expr is executed, $binval is evaluated and substituted so the expression I am evaluating is

Code:

set mask 0x80
if { [expr ('B' & '0x80') > 0] } {...}
etc...

Eventually I got it working by converting the $binval into a '0x42' string value, like this:

Code:

binary scan $binval c byte
set byte [format "0x%0x" $byte]
set mask 0x80
if { [expr ($byte & $mask) > 0] } {...}
etc...[

Then the expression yields what I want. But this seems so stupid and clumsy. Isn't there a better way where I can compare two binary values without conversions?

View 14 Replies View Related

Programming :: No Match For 'operator<<' In '((HttpRequest*

Jul 13, 2011

I have a simple program from book C++ cookbook, page 291, 8.3, Using Constructors and Destructors to manage resources (or RAII), but it can not get compiled in my g++

------------------------------------------------------------------------------------------------
// Example 8-3. Using constructors and destructors
#include <iostream>
#include <string>
using namespace std;

[code]....

View 2 Replies View Related

Programming :: Getting A Comparison Operator To Work?

Feb 8, 2010

I'm very new at Bash scripting and have a bone head issue that I'm trying (and failing) to resolve. I cannot get this one IF statement to work, it seems the comparison operator does not think the resulting number from the $b*$c+$b operation is an integer even though it is a number. Below is a small proof of concept script with the bit I'm having trouble with.

Code:
#! /bin/bash
a=800
b=700
c=.15
if [ "$a" -le "$(echo "($b*$c+$b)"|bc)" ]

[Code]...

View 6 Replies View Related

Debian Programming :: Square Bracket Operator?

Sep 1, 2014

Is there a way to achieve the following with the square bracket operator?I have a class:

Code: Select allclass A
{
public:
    void SetValue(int index, Item* B);
private:
    int m_iCount;
    ItemCollection Item_Collection;

[code]....

The probelm is that I am not just blindly assigning whatever given on the right hand side to the returned value from operator [], I need to verify it's not NULL, and it is not already there in the Item_Collection, and I also need to increase the count.

View 5 Replies View Related

Programming :: Operator For Floating Point Comparison?

May 10, 2011

I know it is wrong to use the "==" operator to compare the equality of two floating point numbers. Logically it would seem that if the "==" operator is not usable for floating point comparison, then the "<=" operator would also not be usable. Is this true? The lack of google search results on this topic made me think that it must be true. If that is true, then is it true that the only way to compare floats with <= or >= is with something like the code below? Code: bool smaller_than_or_equal(float a, float b) {

if ( fabs(a-b) < EPSILON){return true;}
else if (a < b) {return true;}
else {return false;}

} I think this is a general question, but if specifics are necessary, I am using the C++ language to code at the moment.

View 5 Replies View Related

Programming :: C++ Cin Doesn't Wait For Input By Operator

Jan 4, 2010

I am trying to learn C++.I implemented a simple archive program, and I am in a situation in which the user is prompted by a menu to make a choice.So I have some cout instruction to illustrate the possible choices and then

int choice;
cin>>choice;

and everything works fine.I introduced this code in a "while" loop that checks wether the choice made by the user is valid or not:

bool check=true;
int choice;
while(check)
{
cin>>choice;
if(the choice is valid) {...;check=false}
else cout<<"please make an other choice"
}

What is happening is that if by mistake the user introduces a character in place of a number, the loop repeats indefinitely because the program, when it get to the "cin" instruction, does not pauses to wait for a new input.

View 7 Replies View Related

Programming :: Print Increment Operator In Perl?

Apr 25, 2010

Can one of you point me towards a comprehensive print function tutorial in perl? I was under the impression that everything within quotes will get interpolated - but I am running into exceptions where it is not desirable to run some varaibles under quotes.

ordinal.pl
1 #!/usr/bin/perl
2 $idx = 1;
3 foreach $letter (a..z) {
4 print "Letter #",$idx++," is: $letter
";
5 #print "Letter # $idx++ is: $letter

[Code]...

View 9 Replies View Related

Programming :: Python Equivalent Of C Ternary Operator?

Jun 12, 2010

I've been reading and googling, etc. I've seen some things, but not a definite explanation of this. What is the appropriate way to mimic a C ternary operator using Python? Isn't there an exact proper way to do it? Any difference for using lambda functions? I'm sorry, but I've been searching and it's ambiguous to me how this should be handled. I would appreciate a person's help on this. I came up with this link, but I'm wondering if I'm missing something.[URL]...

So, is that it? In Dive Into Python, it's using the and-or trick. Well, if the above post is the full explanation,

View 6 Replies View Related

Programming :: Subscript Operator For A List Class?

Jun 27, 2010

how to overload the subscript operator ([]) for a list class?

Code:
template <typename T>
class list
{
public:
struct node

[Code]...

View 1 Replies View Related

Programming :: String Comparison - [: =: Unary Operator Expected?

Nov 23, 2010

I would like to compare the nmlookup result of IP's stored in the file ips with a list of PC names stored in the file pcs.

Code:
for line in `cat "ips"`
do

[code]....

View 2 Replies View Related

Programming :: Bash - Read Content Of File To Variable And Use This Variable In For Loop ?

Aug 21, 2009

I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.

For example:

Code:

Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).

View 6 Replies View Related

Programming :: Make A New Variable With The String From The Old Variable Btut Without Any Plus Sign?

Apr 7, 2010

my script has a variable which comes in the form +00.00 +0.00 -00.00 or -0.00 (the numbers can be any in that form) for any that have a + symbol I need to remove the +, but if it has a - symbol it needs to stay.

i need to make a new variable with the string from the old variable btut without any plus sign. I have tried a lot of different ways with no success, each thing I tried either left the + or removed the entire string. I think this should work but doesn't

foo=+12.40
bar=${foo#+}

View 4 Replies View Related

Programming :: C++: Assignment Operator Copy All The Members Also For Structures Containing STL Objects?

Sep 26, 2010

does the assignment operator copy all the members also for structures containing STL objects strings,vectors,vectors of vectors...)? I did try it on my platform,and it works that way (copying all the fields),but i was wondering if it is a standard behavior or not.

View 2 Replies View Related

Programming :: Search Within A Variable And Assign The Results To A New Variable?

Apr 25, 2011

how I can search within a variable and assign the results to a new variable. I'll use the following as an example -

cars="Audi BMW Cadillac Chevy Dodge Ferrari Ford Mercedes"
list=`echo ${cars} | egrep -o '<A?+|<C+'`

with the echo command I get the following output assigned to list -

A
C
C

What I'd like to get for output is -

Audi
Cadillac
Chevy

how I could do this regardless of upper/lower case letters?

View 5 Replies View Related

Programming :: Double Quotes Inside Double Quotes?

Jun 6, 2010

In bash I need to use some equivalent of double quotes inside double quotes (or the other way around.)I need to run the following statement to get the output of foo and store it in a variable while passing foo the $file which probably contains spaces.

Code:
variable=$(foo "$file")
The problem is that foo might return an empty string and if it does I need to catch it

[code]...

View 6 Replies View Related

Programming :: Assign Value Of C Variable To Shell Variable?

Apr 28, 2010

included shell script inside c program, and i wanted to assign the value of c variable to shell variable..Can any one please suggest me how to do it?

View 8 Replies View Related

Programming :: Assignment To A Variable Variable?

Mar 17, 2011

This loop is part of a bash script which takes multiple arguments.

Code:
for ((i=1;i<=$number;++i)) ; do
offset=$(($i+5))

[code]...

View 3 Replies View Related

Programming :: Bash Scripting With "source" Or . (dot) Operator (Cygwin & Ubuntu)?

Jan 22, 2010

This one is driving me crazy.

My .bashrc is set as:
if [ -d ~/.bashrc.d ]; then
for file in $(/bin/ls ~/.bashrc.d/); do

[code]....

View 3 Replies View Related

Programming :: Change Or Add Paths For The Compiler To Look In When Using The "<>" Operator?

May 12, 2010

My compiler won't find <new>. Since it's such a basic function, I'm a bit confused. Is <new> supposed to be in a file of its own? Where do I find it? And if it turns out to be missing on my computer, where can I find a <new> one? Or do you see anything else that I do wrong?

After some trying out, it seems I can't find stuff like iostream or any other basic stuff either. The compiler is prolly looking for them at the wrong place. Does anyone know how I change or add paths for the compiler to look in when using the "<>" operator?

View 2 Replies View Related

Programming :: Convert From Hex String To Double In C/c++?

Apr 5, 2010

Someone know how i can convert from hex string to double in c/c++?? Example 40668472B020C49C is 180.139

reference page: http://babbage.cs.qc.edu/IEEE-754/64bit.html

View 10 Replies View Related

Programming :: Using /dev/random To Generate Double?

Mar 6, 2010

I need to generate random numbers using /dev/random in C. The numbers should be of type double (64-bit floating point).The functionality should be equal to linux command "od -An -N8 -t fD /dev/random", but written in C.The prototype should be "double drand(void);".

View 7 Replies View Related

Programming :: Ignoring Commas Within Double Quotes?

Nov 4, 2010

I'm trying to write a bash script that has to extract values from a csv file. Problem is there are lines like this:a,b,c,"dd,dd,dd",e,f,gI'm using awk to extract the values but when I try it extract value 4 with awk I get:"ddinstead of:"dd,dd,dd"Does anyone know how to get awk to ignore commas within double quotes?

View 5 Replies View Related

Programming :: Double Data Type Mantissa?

Nov 23, 2010

in c/c++, double is usually 8 bytes. It has a 52-bit mantissa (or significand, or base), an 11-bit exponent, and a 1-bit sign. My question is: is the mantissa a 52-bit integer? Or is the decimal point just after the first bit. Meaning: if the mantissa was 1000110011100011 (in binary) would that make the value of the mantissa (assuming the exponent was 0) 1000110011100011, or 1.000110011100011? (in binary)

View 1 Replies View Related

Programming :: [C++] Writing Double Value To A Text File?

Jun 3, 2011

Code:
int main ()
{

[code]...

View 9 Replies View Related

Programming :: Bubble Sort For Array Of Double?

May 10, 2010

Here's my code for bubble sort with double type

Code:
#include <stdio.h>
void swap_double( double *a, double *b )
{
double _t = *a;
code....

View 1 Replies View Related

Programming :: Remove Double Quotes Bash?

Jul 20, 2011

grep -e XkbLayout /etc/X11/xorg.conf | grep -v "^#" | awk '{print $3}'

output = "gb"
sometimes= "us"

View 4 Replies View Related

Programming :: SED - Convert Double Quote To Single

Jan 21, 2010

I want to convert double quote to single quote in a text file. I tried escape characters however no success. Please find details as follows:

-sh-3.00$ sed 's/"/'/g test.txt
sed: -e expression #1, char 7: unterminated `s' command
-sh-3.00$ cat test.txt
"unix"

I want "unix" to be converted to 'unix'

View 7 Replies View Related







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