HI guys! I need a lil help. Im new at C++ Programming and Im stuck at creating a simple program that will have this output:
if i enetered any word say alpha, it will be dislpayed as:
a
l
p
h
a
Your input method will depend on what you want to input, either a single word or something with spaces in it, this will determine the method used for input.
#include <iostream>
#include <string>
int main()
{
// std::string: https://cal-linux.com/tutorials/strings.html
// a string can hold all the characters in any word
// (we always use std::string to represent a sequence of characters)
std::string word ;
std::cout << "enter a word: " ;
std::cin >> word ; // reads a single word entered by the user into the string
// range based loop: http://www.stroustrup.com/C++11FAQ.html#for
// a range based loop is the simplest, and the least error prone looping construct
// so we favour this kind of loop over others, whenever it can do the job for us
for( char c : word ) // for each character c in the word
std::cout << c << '\n' ; // print it out, followed by a new line
}