-1

// function which populates the value of currentTemp and maxTemp

  result = smartHlpTemperatureGet( &sh, &currentTemp, &maxTemp );

// Adding maxTemp and currentTemp to the structure after gettin

diskDataT->currentTemp = currentTemp;
diskDataT->maxTemp = maxTemp;

// Following cout is printing the value properly

cout<<"Temperatures - Current"<<currentTemp<<"Max Temperature ="<<maxTemp<<endl;

//structure in which the above variables are declared

  struct diskDataDetailed
{

   uint8_t currentTemp;
   uint8_t maxTemp;

}

//Does not print the value of currentTemp

cout<<diskDataT->currentTemp<<endl;

//Output for above cout

$

I don't understand where I am going wrong.

Alan Stokes
  • 18,815
  • 3
  • 45
  • 64
Vinay Shukla
  • 1,818
  • 13
  • 41
  • Possible duplicate of [How to output a character as an integer through cout?](http://stackoverflow.com/questions/14644716/how-to-output-a-character-as-an-integer-through-cout) – Alan Stokes Dec 23 '15 at 14:13
  • @AlanStokes does it also apply to structure ? My concern was why the value in the structure is not printing whereas normal variable value is getting printed properly. – Vinay Shukla Dec 23 '15 at 14:15
  • Unless you're storing millions of these it would be easier to use plain `unsigned int` for your values. – Alan Stokes Dec 23 '15 at 14:15
  • It applies to any value of a `char` type regardless of where you get it from. I bet your variable is not of type `uint8_t`. – Alan Stokes Dec 23 '15 at 14:17
  • @AlanStokes yeah adding `+` displayed the value in proper format can you help as to how can i populate the structure`diskDataT->currentTemp` with this value – Vinay Shukla Dec 23 '15 at 14:30

1 Answers1

0

You already have the right value, but because it is of type unsigned char (which is what uint8_t is on your system) the default behaviour is to print it as a character not a number.

As I said above replacing uint8_t with unsigned int would make things slightly easier. Otherwise you just need to remember to convert the value to a wider type before you print it - that's what the + does.

Alan Stokes
  • 18,815
  • 3
  • 45
  • 64
  • Alan, I agree with you and your solution worked for printing but I wish to know how can i populate the structure with this value I tried this. ` diskDataT->currentTemp = +currentTemp; diskDataT->maxTemp = +maxTemp;` but this did not work. I cannot use unsigned int because it is a header file change – Vinay Shukla Dec 23 '15 at 14:37
  • You only need the `+` for output. `diskDataT->currentTemp = currentTemp` is just fine. The problem is not the value or the variable; it is only how you print it. You have to apply the `+` at the time of printing and not before. If you don't want to do that, stop using `uint8_t`. – Alan Stokes Dec 23 '15 at 14:41