回文过滤器,函数运行良好,但main()无法编译
Palindrome Filter, the functions work perfectly, but the main() doesn't compile
编译器给我一个错误,我尝试了包括周期的所有内容,但它没有帮助,也许有人有一个想法?功能非常有效,但是主((部分不
#include <iostream>
#include<vector>
using namespace std;
bool IsPalindrom(string s) {
for (size_t i = 0; i < s.size() / 2; ++i) {
if (s[i] != s[s.size() - i - 1]) {
return false;
}
}
return true;
}
vector <string> PalindromFilter(vector<string> words, int min_Length){
vector<string> result;
for(auto s : words){
if (s.size() >= min_Length && IsPalindrom(s)){
result.push_back(s);
}
}
return result;
}
int main(){
cout << PalindromFilter({"abacaba", "aba"}, 4);
}
请注意PalindromFilter()
函数的返回类型。它返回字符串的向量。您不能使用cout
直接打印向量的内容。
相反,您可以尝试存储返回的值并使用显示功能。您的参考代码:
// Function to display elements of the vector of strings
void Display(const vector<string> & vec)
{
for (int i = 0; i < vec.size(); i++)
{
// Note that for printing a string you need to
// use c_str()
cout << vec[i].c_str() << endl;
}
}
在主要功能中:
int main()
{
vector<string> output = PalindromFilter({ "abacaba", "aba" }, 4);
Display(output);
return 0;
}
相关文章:
- 尝试更改 main 函数内的全局变量值时出现编译错误 C++.
- 在 Linux 上编译 - 在函数 '_start' 中:(.text+0x20):对 'main' 的未定义引用
- int main = 0,已编译但崩溃
- std::具有initializer_list和size的unordered_map构造函数在main中编译,但不在类定
- 编译mbed操作系统程序时"multiple definition of `main'"错误
- 回文过滤器,函数运行良好,但main()无法编译
- 当使用 /ENTRY:main 和 /MT 运行时库编译为 /SUBSYSTEM:WINDOWS 时,应用程序崩溃
- 单元测试 - 仅在"int main()"左右重新编译以减少编译时间
- C++ 编译错误:- 使用Makefile对"main"进行多重定义
- C++编译错误:多个定义"main",但项目中只有一个 main 函数
- GC/C++ 从编译中省略了 main,在单独的文件中提供 main
- 如何编译这C++"'::main' must return 'int'"失败的代码?
- 在编译时替换对象文件中的符号.例如,换掉main
- 尝试使用 MinGW 编译 Assembly + C++:ccqKAvXJ.o:main.cpp:(.text+0x18):对 'GetMagicNumber' 的未定义引用
- 编译php-cpp main.cpp文件时出错
- 使用 -g 选项编译,但"Single stepping until exit from function main, which has no line number information"
- 生成文件编译的 C++ 错误,无法转换 main()::
- 在没有Main的情况下编译C程序
- 如果一个类不是直接从main中使用的,但有一个静态私有成员,那么在编译和链接时,可以使用最大优化来忽略它吗
- 在编译main.cpp:3:1时,我一直得到这个错误:error: ' do '之前的expected unqual