c++ - 在变量或字段 'printVector' 声明为 void 之前缺少模板参数

标签 c++ c++11

我遇到了这两个错误,但我无法弄清楚。我基本击中了编码 block 。

变量或字段 'printVector' 在

之前声明为无效且缺少模板参数
#include <iostream>
#include <vector>
#include <cctype>
using namespace std;

void printVector(vector<string> vec);

int main() {

vector<string> ivec;


cout<<"Please your sequence of words and ctrl-z to stop"<<endl;
string input;

while(getline(cin, input)){
    ivec.push_back(input);
}

cout<<"Your input is: \n";

for(std::vector<string>::iterator it = ivec.begin(); it != ivec.end(); ++it ){
    cout<<*it<<"";
  }

cout<<"Your input changed to upper case: "<<endl;
printVector(ivec);
return 0;
}


void printVector(vector<string> vec){
for(auto &v: vec){
    for(auto &c: v)
        cout<<toupper(c)<<"";
    }

}

更新:

void printVector(vector<string> vec){


// process characters in s until we run out of characters or we hit a whitespace
for (auto it = vec.begin(); it != vec.end() && !isspace(*it); ++it)
        *it = toupper(*it);


错误:

无效参数 ' 无效参数 '

没有用于调用“toupper(std::basic_string&)”的匹配函数

最佳答案

你需要添加

#include <string>

到你的程序。
std:string未声明编译器无法将其识别为 std::vector<std::string> 的有效模板参数.

关于c++ - 在变量或字段 'printVector' 声明为 void 之前缺少模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32163560/

相关文章:

android - 在 Android Studio 中使用共享库时出现 UnsatisfiedLinkError

c++ - 将数字合并到对象的名称

c++ - 在 C++ 中重命名(别名/转发)函数的最佳方法是什么?

c++ - 如何检测整个周期的C++随机引擎已经被消耗

C++ 视频流检测 FPS

c++ - 为什么两种情况下数组的大小都不相同?

java - 如何检查 JNI 中的内存泄漏

c++ - 带有类的模板特化

c++ - 从我的 dylib 调用带有 std::string 参数的成员函数会产生 "Undefined symbols"错误

c++ - 为什么此代码无法使用 gcc 4.8.5 进行编译,而使用 clang 可以正常编译