anonymous
  • anonymous
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?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Yes you must write gets(variable); to input spaces as well .
anonymous
  • anonymous
I don't understand what you mean. Is gets a function? Perhaps you could show me with code.
anonymous
  • anonymous
I want to say this: #include #inlcude #inlucde int main() { char name[20]; gets(name); cout<<"\n"<

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
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++.
anonymous
  • anonymous
Yes you can use this to string as well.
anonymous
  • anonymous
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.
anonymous
  • anonymous
^ 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 ;)
anonymous
  • anonymous
I need your help in python.
anonymous
  • anonymous
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

Looking for something else?

Not the answer you are looking for? Search for more explanations.