Quote:
Have recently started c++ , gone through basic. Assignment was to convert it into python code which I have done but I want to experiment it in c++. I am quite new to it, so I could only do input and output but got stuck in the loop no idea how to write it
Even your Python code is missing the
+3
part.
But in C/C++ it is much simpler. If you have C string (
char
array) or a
std::string
you can access the array by index /
[]
operator:
input[i] += 3;
Note that the above code snippet assumes that output has been initialised with a copy of the input string.
Alternatively use a
Range-based for loop (since C++11) - cppreference.com[
^] :
std::string output;
for (auto c : input)
output += c + 3;