Я создал программу на С ++, которая может быть либо по правому краю, либо по левому краю, но в нижней части появляется ошибка, касающаяся "<", "<<", ">", ">>". операторы. Я также предоставил изображение, чтобы показать, с какими ошибками я сталкиваюсь. Мне нужно решить эту проблему, если кто-то может мне помочь, это было бы очень признательно.
Вот изображение ошибки
#include <iostream>
#include <cstring>
using namespace std;
string leftIndent(string &input, const int length) {
bool inword = false;
string output;
string word;
int added = 0;
for (int i = 0; i < input.length(); i++) {
if (input[i] == ' ') {
if (inword == true) {
if (word.length() > length) {
// What happen if a word larger than a line?
}
added += word.length();
if (added > length) {
output.append(1, '\n');
output.append(word);
added = word.length();
word = "";
}
else {
output.append(word);
word = "";
}
if (added + 1 <= length) {
output.append(1, ' ');
added++;
}
}
inword = false;
}
else {
word += input[i];
inword = true;
}
}
if (!word.empty()) {
if (word.length() > length) {
// What happen if a word larger than a line?
}
else if (word.length() + added > length) {
output.append(1, '\n');
output.append(word);
}
else {
output.append(word);
}
}
return output;
}
string rightIndent(string &input, const int length) {
bool inword = false;
string output;
string word;
string line;
for (int i = 0; i < input.length(); i++) {
if (input[i] == ' ') {
if (inword == true) {
if (word.length() > length) {
// What happen if a word larger than a line?
}
if (line.length() + word.length() > length) {
if (line.back() == ' ') line.erase(line.length() - 1);
for (int j = 0; j < length - line.length(); j++) output.append(1, ' ');
output.append(line);
output.append(1, '\n');
line = word;
word = "";
}
else {
line.append(word);
word = "";
}
if (line.length() + 1 <= length) {
line.append(1, ' ');
}
}
inword = false;
}
else {
word += input[i];
inword = true;
}
}
if (!word.empty()) {
if (word.length() > length) {
// What happen if a word larger than a line?
}
else if (line.length() + word.length() > length) {
if (line.back() == ' ') line.erase(line.length() - 1);
for (int j = 0; j < length - line.length(); j++) output.append(1, ' ');
output.append(line);
output.append(1, '\n');
for (int j = 0; j < length - word.length(); j++) output.append(1, ' ');
output.append(word);
}
else {
line.append(word);
for (int j = 0; j < length - line.length(); j++) output.append(1, ' ');
output.append(line);
}
}
return output;
}
int main()
{
string str = "";
cout << leftIndent(str, 20);
cout << endl << endl;
cout << rightIndent(str, 20);
return 0;
}