注册 登录
编程论坛 C++教室

编译器提示“ error: ld returned 1 exit status”在怎么解决呢??

a75692074 发布于 2018-07-27 10:42, 4659 次点击
#include <iostream>
using namespace std;

void n_chars(char, int);

int main()
{
    int times;
    char ch;
   
    cout << "Enter a character: ";
    cin >> ch;
    while (ch != 'q')
    {
        cout << "Enter an integer: ";
        cin >> times;
        n_chars(ch, times);
        cout << "\nEnter another character or press the"
                " q-key to quit: ";
            cin >> ch;
    }
    cout << "The value of times is " << times << ".\n";
    cout << "Bye.\n";
    return 0;
}

void n_chars(char c, char n)
{
    while (n-- > 0)
        cout << c;
}

然后编译的时候就提示“error: ld returned 1 exit status”
怎么解决呢?谢谢大家!

[此贴子已经被作者于2018-7-27 10:44编辑过]

3 回复
#2
a756920742018-07-27 10:43
只有本站会员才能查看附件,请 登录
#3
rjsp2018-07-27 12:28
不要贴图,而应该将错误信息贴出来
错误信息 不是指“ error: ld returned 1 exit status”这句
而是指“undefined reference to n_chars(char,int)”这句

这句错误提示说得很清楚了,你声明了 void n_chars(char, int),但却没它的定义。
看你的代码,真没它的定义,只有一个 void n_chars(char c, char n) 的定义
#4
a756920742018-07-27 12:51
回复 3楼 rjsp
好的,谢谢
1