【问题标题】:I want to call my function with string parameter我想用字符串参数调用我的函数
【发布时间】:2014-09-11 16:27:37
【问题描述】:
void GenerateDecryptedData("/home/merve/merve.enc", "/home/merve/merve.dec","dEneMe!1234");

我想像 dEneMe!1234 这样调用我的函数。

void GenerateDecryptedData(const char* pathToEncryptedFile, 
                        const char* pathToDeccryptedFile,
                        std::string Pwd);

但是当我写这样的函数原型时,我取的是string还没有被声明——错误!如何获取字符串类型的密码?

【问题讨论】:

  • 添加#include
  • 我添加了 #include 。这还不够吗? @0d0a
  • No 是不同的库(继承自 C)
  • 顺便把前两个参数也改成std::string比较好

标签: c++ string function function-calls


【解决方案1】:

您需要源文件顶部的字符串标题:#include <string>。我会考虑更频繁地使用谷歌搜索错误消息。 :)

字符串标题 - http://www.cplusplus.com/reference/string/
cstring 标头 - http://www.cplusplus.com/reference/cstring/

【讨论】:

    【解决方案2】:

    有什么问题:

    void GenerateDecryptedData(const char* pathToEncryptedFile, const char* pathToDeccryptedFile, const char* Pwd);
    

    【讨论】:

    • 我也试过这个,但它说“dEneMe!1234”有问题,为什么我这样称呼?
    • 如果你试过了,你为什么不说呢?发布您已经尝试过的信息,以及您尝试后发生的情况。
    • 我知道——欢迎来到 Stack Overflow!将这些作为编辑添加到您的问题中,而不是此处的 cmets。另外,试试科林的回答。
    • 天哪!答案一直在写。这是一个函数调用而不是函数声明。非常抱歉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 2021-10-12
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多