Help with entering a string that includes spaces in C++. I'm doing the first problem of problem set 1 for Stanford CS106B. The goal is to remove all instances of a target string from a source string and return the source. Here's the code I have: http://pastebin.com/4YuNADaa It works for all "solid" strings but crashes when I put something in with spaces. Any help?
Yes you must write gets(variable); to input spaces as well .
I don't understand what you mean. Is gets a function? Perhaps you could show me with code.
I want to say this: #include<iostream.h> #inlcude<conio.h> #inlucde<conio.h> int main() { char name[20]; gets(name); cout<<"\n"<<name; return 0; getch(); }
Hmm, so we're using the char type... any reason for that? Can I use the same find functions, etc for a char that I can for a string? Or might I be able to convert the char to a string? I'm new to C++.
Yes you can use this to string as well.
OK, I used the string() function and it seems I'm done! Thanks a bunch! Seems like an unnecessary step... but I'm used to Python, hehe. I'm sure this way has its reasons/advantages. Anyway, thanks again.
^ I mean to say I combined what you suggested to get the character input and then put that in the string function to convert to a string ;)
I need your help in python.
Only avoid using gets(). Such a bad function for generic I/O. Use fgets() instead. Read more about it here: http://www.gidnetwork.com/b-56.html
Join our real-time social learning platform and learn together with your friends!