回 帖 发 新 帖 刷新版面

主题:string with no type

大虾帮忙找找问题出在哪里?
devcpp编译时出现
14 E:\cpp files\page 23(4).cpp ISO C++ forbids declaration of `String' with no type 程序如下
#include<iostream.h>
#include<string.h>
using namespace std;
class Stirng
{
      int length;
      char*str;
public:
       String(char*);
       String(const String &p) ;
       void Show(){
            cout<<str<<endl;}
};
String::String(char*s){
        if(s){
              length=strlen(s);
              str=new char[length+1];
              strcpy(str,s);}
        else{
             length=0;
             str=0;}
             }
String::String(const String &p){
                     length=p.length;
                     str=new char[length+1];
                     strcpy(str,p.str);
                     }
main(){
       String str1("This a constructing.");
       String str2(str1);
       cout<<"str1:";
       str1.Show();
       cout<<"拷贝后\nstr2:";
       str2.Show();
       getchar();
}

回复列表 (共3个回复)

沙发

首先class string 都会写错 无语

板凳

还有有了.h 要 using 干吗、
main 默认了 有返回值 警告。。
同时getchar() 在 stdio.h里

3 楼

多谢了。
是class String写错了
还有就是可以不用“using namespace std;”

我来回复

您尚未登录,请登录后再回复。点此登录或注册