I am running a program that initializes a vector full of integers, assigns randomly generated integers to it, does a bubble sort on the integers, and then finds the kth largest integer (determined by the size of the integer divided by two). I have run my program in a Unix shell and everything works except for the finding of the kth largest integer. When I run my program, this is the error that is printed to the console:
"warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘std::__cxx11::string* {aka std::__cxx11::basic_string<char>*}’ [-Wformat=]
printf("Program will now find the %s largest integer:", k);"
I have looked at the cplusplus documentation for "printf" and I am pretty sure I used the right specifier for returning a string (%s), but the compiler says it is expecting the "char*" specifier. Does anyone know why this is happening?
I have looked at the cplusplus documentation for "printf" and I am pretty sure I used the right specifier for returning a string (%s), but the compiler says it is expecting the "char*" specifier. Does anyone know why this is happening?
Well C doesn't know anything about C++ strings why would you expect a C function to know how to print a C++ string?
Your best bet is to stop using the C-stdio function like printf() and scanf() and use C++ streams like cin, and cout instead.
In other words if you want to write a C++ program use C++ methods. If you'd rather write a C program then stick with C features instead of C++ features like std::string.