Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ program that put a space in between characters

#include <iostream>
#include <string>

std::string Spaced(std::string userString);

int main()
{
   std::cout << "Enter a string: ";
   std::string userString;
   std::getline(std::cin, userString);

   std::string spacedString = Spaced(userString);
   std::cout << "
The spaced string is:
" << spacedString << '
';
}


std::string Spaced(std::string userString)
{
   std::string spacedString;

   for (auto itr : userString)
   {
      spacedString += itr;
      spacedString += ' ';
   }

   return spacedString;
}
Source by cplusplus.com #
 
PREVIOUS NEXT
Tagged: #program #put #space #characters
ADD COMMENT
Topic
Name
7+4 =