Search
 
SCRIPT & CODE EXAMPLE
 

CPP

print a string with printf in c++

//can't print with printf, since string is a C++ class obj and print %s 
//doesn't recognize
//can do
printf("%s", str.c_str()) //converts string to c str (char array)
  
  //or just use cout<<str; 
  
  //string assignment 
  str1=str2; //or
str1.assign(str2) 
Comment

printf in c++

#include <cstdio>

int main(){

char c = 'S';

float x = 7.0, y = 9.0;

double d = 6.548;

int i = 50;

printf("The float division is : %.3f / %.3f = %.3f 
", x,y,x/y);

printf("The double value is : %.4f 
", d);

printf("Setting the width of c : %*c 
",3,c);

printf("The octal equivalent of %d is %o 
",i,i);

printf("The hex equivalent of %d is %x 
",i,i);

return 0;

}
Comment

PREVIOUS NEXT
Code Example
Cpp :: stringstream stream number to string 
Cpp :: is power of 2 
Cpp :: factorial function c++ 
Cpp :: vector::insert 
Cpp :: char size length c++ 
Cpp :: c++ encapsulation 
Cpp :: opencv open image c++ 
Cpp :: initialize string with length c++ 
Cpp :: c++ add to array 
Cpp :: vector find 
Cpp :: power of two c++ 
Cpp :: print duplicate characters from string in c++ 
Cpp :: unique_ptr syntax 
Cpp :: how to know datatype of something in c++ 
Cpp :: #define online judge in cpp 
Cpp :: c++ check if string is isogram 
Cpp :: find in vector 
Cpp :: convert int to string in c++ 
Cpp :: C++ Conditions and If Statements 
Cpp :: c++ thread 
Cpp :: Visual studio code include path not working c++ 
Cpp :: size() in c++ SET 
Cpp :: check even or odd c++ 
Cpp :: how to convert string to int in c++ 
Cpp :: how to make a function in c++ 
Cpp :: pass map as reference c++ 
Cpp :: How to use jwt in login api in node js 
Cpp :: Integer Moves codeforces solution 
Cpp :: hierarchical inheritance in c++ employee 
Cpp :: linear search 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =