如何解决我需要一些指导,以用数组替换代码中的所有向量
我写了一个程序来对普通文本文件进行编码,压缩文本。我今天整天都在忙着处理它,却没有意识到我不能在代码中使用向量,而应该使用数组。由于未知的原因,我不太擅长使用数组。我有一部分代码要分享,我希望有人可以引导我完成将向量转换为数组的步骤。我没有发布完整的代码,因为它是针对一个类的,但是如果需要,我可以添加更多代码。
#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 举报,一经查实,本站将立刻删除。