Skip to main content
MMARI.1
Senior II
December 25, 2022
Question

prinf and scanf will not work in c++ .please share with complete solution cout and cin usage in c++

  • December 25, 2022
  • 2 replies
  • 1559 views

..

    This topic has been closed for replies.

    2 replies

    Pavel A.
    December 25, 2022

    Why? printf and scanf work great in c++. # include <cstdio>

    MMARI.1
    MMARI.1Author
    Senior II
    December 25, 2022
    #include "main.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */ uint8_t display[] = "2555 \r\n"; volatile uint8_t flag =0; volatile int counter = 0; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART1_UART_Init(void); /* USER CODE BEGIN PFP */ #ifdef __GNUC__ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif PUTCHAR_PROTOTYPE { HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, HAL_MAX_DELAY); return ch; } no compile error .. #include but no ouput in serial monitor . #include it's working
    December 26, 2022

    Use printo("text", double, float, uint(8-16-32-64)_t, int(8-16-32-64)_t ). Any parameters without restrictions, in any order.

    https://github.com/AVI-crak/Rtos_cortex/blob/master/sPrint.h

    Before using, define the string output function - soft_print(char* txt)

    Works very fast.