Answers for "example of printf c++"

C++
5

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)
Posted by: Guest on May-25-2021
0

c++ custom printf

int aclass::printf(const char * format, ...) {
	if (this->silent > 0) return 0;

	va_list arg;
	int done;

	va_start(arg, format);
	done = std::vfprintf(stdout, format, arg);
	va_end(arg);

	return done;
}
Posted by: Guest on March-16-2022

Browse Popular Code Answers by Language