Feb 16, 2017 at 4:09pm UTC
oh .. then why it's in the cplusplus reference ?
Feb 16, 2017 at 4:16pm UTC
The reason im using scanf is that it omit spaces so basically it saves me some time of coding
Feb 16, 2017 at 4:22pm UTC
oh .. then why it's in the cplusplus reference ?
C is still part of C++ that's probably the reason.
If you really need to use scanf and a string, here's a way to do it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <string>
#include <cstdio>
int main()
{
// Just a proof of concept - not really advisable to do
std::string buffer(10, ' ' );
printf("Your input: " );
scanf("%9s" , &buffer[0]);
printf("\n%s" , buffer.c_str());
system("pause" );
return 0;
}
Last edited on Feb 16, 2017 at 4:35pm UTC
Feb 16, 2017 at 4:39pm UTC
Have a look at the post above yours - probably you didn't see my edit.
Feb 16, 2017 at 4:52pm UTC
Cool so basically %9s iterate over the string which is basically an array of chars .. thanks was a big deal of help ^^
Last edited on Feb 16, 2017 at 4:53pm UTC