我的程序中出现了访问冲突(分段错误)

时间:2015-08-08 02:23:04

标签: c++

我正在使用Dev C ++作为编译器。当我运行以下程序时,它说“出现了访问冲突(分段错误)”。我不知道该程序有什么问题。有人可以帮忙吗?谢谢!

#include <iostream>
#include <string>
using namespace std;


class Solution {
public:
    string convert(string s, int numRows) {
        int len;
        len = s.length();
        cout<<len<<endl;
    }
};

int main ()
{
    Solution sol;
    string s;
    s = "hi";
    sol.convert(s,3);

    return 0;
}

1 个答案:

答案 0 :(得分:4)

您在函数convert()中缺少return语句。您需要将其设为void函数或从中返回一个字符串。