Hey guys,
I am working on a assignment. I am 90% done with the code. However I stuck on the part where i have to flip the output(vertically and horizontaly). I tried I everything i could. I tried setting the row up side down that way it would help and it does flip this way however the output spacing is incorrect. Anyhelp would be great
Thanks!

Dani AI

Generated

wanted to flip printed output vertically and horizontally. asked for code and correctly pointed out that reversing a string is how to flip a line. The spacing problem usually happens when some lines are shorter than others: reversing without equalizing widths shifts columns. The safe approach is to treat the input as a rectangular grid — pad every line to the same width, then apply the flips.

A minimal workflow:

  • Read all lines into a vector<string>.
  • Compute the longest line length and right-pad every line to that length (fill with spaces).
  • Horizontal flip: reverse characters in each string (use std::reverse).
  • Vertical flip: reverse the order of the lines (reverse the vector).
  • Print each line.

Example code (minimal):

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
    std::vector<std::string> lines;
    std::string s;
    while (std::getline(std::cin, s)) lines.push_back(s);
    size_t maxlen = 0;
    for (auto const& l : lines) if (l.size() > maxlen) maxlen = l.size();
    for (auto &l : lines) l.resize(maxlen, ' ');
    for (auto &l : lines) std::reverse(l.begin(), l.end()); // horizontal
    std::reverse(lines.begin(), lines.end());               // vertical
    for (auto &l : lines) std::cout << l << '\n';
}

Notes: expand tabs to spaces before measuring width; console output requires a monospaced font for alignment; and do not reverse raw UTF-8 byte sequences (use a Unicode-aware approach for multibyte characters). See std::reverse for the reversal routine.

Recommended Answers

All 2 Replies

Do you have some code to show for what you say you've done? I'm sure you know by now that we here at Daniweb do NOT provide help without the OP showing some sort of effort. If you post your code, maybe we can point you in the right direction :P

What do you mean by flipping text?
If you want something like this:

evil ----> live

then this should help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.