gpt4 book ai didi

c++ - 程序错误 "error C3861: ' copyString' : identifier not found", 请告诉我为什么?

转载 作者:行者123 更新时间:2023-11-27 22:48:00 24 4
gpt4 key购买 nike

我是编程新手,我正在尝试这个程序将一个字符串复制到另一个字符串,但它显示错误

 "error C3861: 'copyString': identifier not found"

这是我写的代码

#include <iostream>
using namespace std;
int main()
{
char a[8], b[8];
cout << "enter the string a";
cin.get(a, 8);
cout << a;
int len = sizeof(a) / sizeof(char);
copyString(a, b);
int i;
cin >> i;
return 0;
}

/*function that copy one string to another*/

void copyString(char* a, char* b)
{
int i = 0;
while (a[i] != '\0') {
b[i] = a[i];
i++;
}
cout << b << " String is this";
}

请告诉我我哪里弄错了??

最佳答案

要么在main之前提供copyString实现,要么先为它提供一个原型(prototype):

void copyString(char *a,char *b); // prototype of copyString
int main()
{
...
}
void copyString(char *a,char *b) // implementation of copyString
{
...
}

关于c++ - 程序错误 "error C3861: ' copyString' : identifier not found", 请告诉我为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41094033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com