我需要一些指导,以用数组替换代码中的所有向量

问题描述

我写了一个程序来对普通文本文件进行编码,压缩文本。我今天整天都在忙着处理它,却没有意识到我不能在代码中使用向量,而应该使用数组。由于未知的原因,我不太擅长使用数组。我有一部分代码分享,我希望有人可以引导我完成将向量转换为数组的步骤。我没有发布完整的代码,因为它是针对一个类的,但是如果需要,我可以添加更多代码

#include <iostream>
#include <string>
#include <sstream>
#include<vector>

using namespace std;
vector<string> originalText;

// This function is designed to grab the last character of each sorted line,and then add it to a new string

string cluster(vector<string> &sortedLines,string og)
{
    string endColumn = " ";
    string clusterize;
    int count = 0;
    int ogIndex = 0;
    
    if(sortedLines.at(count) != " ")
    {
        // This will check and see if there are clustered characters in the endColumn String.
        for (int i = 0; i < sortedLines.size(); i++)
        {
            endColumn.push_back(sortedLines.at(i).back());
        }
        for(int i = 0; i < endColumn.length(); i++)
        {
            int clusterCount = 1;
        
            for (int j = i + 1; j < endColumn.length(); j++)
            {
                if(endColumn.at(i) == endColumn.at(j))      
                {
                    clusterCount++;
                    i++;
                }
                else
                {
                    break;
                }
            }
            clusterize += to_string(clusterCount) + " " + endColumn.at(i) + " ";
        }
    }
    // This will get rid of the last space of the encoded string.
    clusterize = clusterize.substr(0,clusterize.length() - 1);
    
    // This is to see which index the original string is in our sorted vector.
    for (int p = 0; p < sortedLines.size(); p++)
    {
        if (sortedLines.at(p) == og)
        {
            ogIndex = p;
            break;
        }
        
        else
        {
            clusterize = to_string(ogIndex) + "\n\n";
        }
        clusterize = to_string(ogIndex) + "\n" + clusterize + "\n";
        count++;
            
    }
       return clusterize;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)