Q:

Write a program to read strings from the standard input, concatenating what is read into one large string. Print the concatenated string. Next, change the program to separate adjacent input strings by a space

0

Write a program to read strings from the standard input, concatenating what is read into one large string. Print the concatenated string. Next, change the program to separate adjacent input strings by a space.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
#include <string>

void concatenate() {
  std::string total, s;
  while (std::cin >> s)
    total += s;
  std::cout << total;
}

void concatenate_with_space() {
  std::string total, s;
  if (std::cin >> total) {
    while (std::cin >> s)
      total += ' ' + s;
  }
  std::cout << total;
}

int main() {
  //concatenate();
  //concatenate_with_space();

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now