Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

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)
See more answers at brainly.com
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.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
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 #inlcude #inlucde int main() { char name[20]; gets(name); cout<<"\n"<

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

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

Not the answer you are looking for?

Search for more explanations.

Ask your own question