急c++:有一个字符串包含n个字符,写一函数,将此字符串中从第m个字符开始的全部字符复制成另一个字符串。

#include<iostream>
using namespace std;
int main()
{
void copy(char*q1,char*q2,int n);
char str1[10],str2[10];
int m;
cin>>str1>>m;
copy(str1,str2,m);

cout<<"str2:"<<str2;
return 0;
}
void copy(char*q1,char*q2,int m)
{
int i=m;
while(*(q1+i-1))
{*(q2+i-m)=*(q1+i-1);
i++;
}
*(q2+i-m)=0;
}
急求!
编译时出现错误could not deduce template argument for ''from'void'

#include<iostream>
using namespace std;
void copy(char*q1,char*q2,int m);//声明要放在外面
int main()
{
char str1[10],str2[10];
int m;
cin>>str1>>m;
copy(str1,str2,m);

cout<<"str2:"<<str2;
return 0;
}
void copy(char*q1,char*q2,int m)
{
int i=m;
while(*(q1+i-1))
{*(q2+i-m)=*(q1+i-1);
i++;
}
*(q2+i-m)=0;
}追问

不是这个问题,compile的时候是说could not deduce template argument for ''from'void'

追答

就是你声明的位置错了。

追问

还真是,多谢啦~可为啥以前我都把函数声明写在main函数里都没错为啥这次就不行啊。。。

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答