代码之家  ›  专栏  ›  技术社区  ›  Maxpm

C头文件中的字符串

  •  1
  • Maxpm  · 技术社区  · 15 年前

    我的头文件如下:

    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <math.h>
    
    //using namespace std;
    
    std::string StringMultiply(string Str, int Mult)
    {
        std::string Return;
    
        for (int Index = 0; Index <= Mult; Index++)
        {
            Return += Str;
        }
    
        return Return;
    }
    

    编译它会产生很多错误,其中大部分都与缺少 string 数据类型。取消注释 using namespace std; 行修复了它,但我被告知这是头文件中的错误做法。

    3 回复  |  直到 15 年前
        1
  •  8
  •   mikerobi    15 年前

    改变

    std::string StringMultiply(string Str, int Mult)
    

    到

    std::string StringMultiply(std::string Str, int Mult)
    
        2
  •  2
  •   Steve Townsend    15 年前

    你需要有资格 string 作为 std::string 每次你用它的时候如果你评论掉 using 行。返回值 StringMultiply 正确,但参数不正确。

    就我个人而言,我不明白 using namespace std; -我不喜欢打字了。

        3
  •  2
  •   MSN    15 年前

    如果你换了 string Str 具有 std::string Str 在参数列表中,一切都可以编译。到底是什么问题?

    推荐文章