-6

I am fairly new to programming and would like help with my homework. I have no idea where to even start. " 1. Have the user input a sentence 2. Print out the individual words in the sentence, along with the word number So the string "This is a test of our program." should produce: 1. This 2. is 3. a 4. test 5. of 6. our 7. program

This should strip out all spaces, commas, periods, exclamation points." if you can give me some pointers. thanks.

K. Bay
  • 1
  • 1
    Welcome to Stack Overflow. Please take the time to read [The Tour](http://stackoverflow.com/tour) and refer to the material from the [Help Center](http://stackoverflow.com/help/asking) what and how you can ask here. – πάντα ῥεῖ Mar 07 '17 at 18:49
  • start with: http://stackoverflow.com/questions/236129/split-a-string-in-c – NathanOliver Mar 07 '17 at 18:54

1 Answers1

0

You will have to use strings and streams from the standard library. You can start by including the following headers

#include <string>
#include <iostream>

A good starting point would be to look at the introduction here

Try some stuff with std::cout. This method allows you to output content to the console. Start with something easy, such as:

std::cout << "Hello World" << endl;

You can also output the content of a variable the same way:

std::string myString = "SomeText";
std::cout << myString << endl;

std::cout does the opposite. It allows you to capture the user input into a variable.

int myNumber;
std::cin >> myNumber;

or

std::string userInputString;
std::getline(std::cin, userInputString)

Notice that in the second case we're using std::getline. This is because std::cin behaves in such a way that it will stop after the first word if you write an entire sentence.

Now that you've captured the user input string, you can remove undesired characters, split the string, etc.. Look at what is available in the string class. Good luck.

AlexG
  • 1,091
  • 7
  • 15