小白求助!!!string.h在VC++6.0怎么用不了!
c++吧
全部回复
仅看楼主
level 8
ssnhero 楼主
#include<iostream.h>
#include<string.h>
void showLarger(int n1,int n2);
void showLarger(float f1,float f2);
void showLarger(string s1,string s2);
void main()
{
int num1=50,num2=100;
float numA=1.1,numB=9.9;
string str1="Sunny day !";
string str2="Wonderful tonight !";
showLarger(num1,num2);
showLarger(numA,numB);
showLarger(str1,str2);
}
void showLarger(int n1,int n2)
{
if(n1==n2)
cout<<n1<<"equals"<<n2<<endl;
else if(n1>n2)
cout<<"Between "<<n1<<"and"<<n2<<"the larger one is "<<n1<<endl;
else
cout<<"Between "<<n1<<"and"<<n2<<"the larger one is "<<n2<<endl;
}
void showLarger(float f1,float f2)
{
if(f1==f2)
cout<<n1<<"equals"<<n2<<endl;
else if(n1>n2)
cout<<"Between "<<f1<<"and"<<f2<<"the larger one is "<<f1<<endl;
else
cout<<"Between "<<f1<<"and"<<f2<<"the larger one is "<<f2<<endl;
}
void showLarger(string s1,string s2)
{
if(s1==s2)
cout<<s1<<"equals"<<s2<<endl;
else if(s1>s2)
cout<<"Between "<<"\" "s1<<"\""<<endl;
cout<<" and"<<"\" "<<s2<<"\""<<endl;
cout<<" the larger one is "<<"\" "s1<<"\""<<endl;
else
cout<<"Between "<<"\" "s1<<"\""<<endl;
cout<<" and"<<"\" "<<s2<<"\""<<endl;
cout<<" the larger one is "<<"\" "s2<<"\""<<endl;
}
结果是这样:
2012年04月23日 14点04分 1
level 8
ssnhero 楼主
Compiling...
10.cpp
e:\myprojects\第五章\10.cpp(6) : error C2065: 'string' : undeclared identifier
e:\myprojects\第五章\10.cpp(6) : error C2146: syntax error : missing ')' before identifier 's1'
e:\myprojects\第五章\10.cpp(6) : error C2182: 'showLarger' : illegal use of type 'void'
e:\myprojects\第五章\10.cpp(6) : error C2373: 'showLarger' : redefinition; different type modifiers
e:\myprojects\第五章\10.cpp(6) : error C2059: syntax error : ')'
e:\myprojects\第五章\10.cpp(10) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
e:\myprojects\第五章\10.cpp(10) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
e:\myprojects\第五章\10.cpp(11) : error C2146: syntax error : missing ';' before identifier 'str1'
e:\myprojects\第五章\10.cpp(11) : error C2065: 'str1' : undeclared identifier
e:\myprojects\第五章\10.cpp(11) : error C2440: '=' : cannot convert from 'char [12]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
e:\myprojects\第五章\10.cpp(12) : error C2146: syntax error : missing ';' before identifier 'str2'
e:\myprojects\第五章\10.cpp(12) : error C2065: 'str2' : undeclared identifier
e:\myprojects\第五章\10.cpp(12) : error C2440: '=' : cannot convert from 'char [20]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
e:\myprojects\第五章\10.cpp(29) : error C2065: 'n1' : undeclared identifier
e:\myprojects\第五章\10.cpp(29) : error C2065: 'n2' : undeclared identifier
e:\myprojects\第五章\10.cpp(35) : error C2146: syntax error : missing ')' before identifier 's1'
e:\myprojects\第五章\10.cpp(35) : error C2182: 'showLarger' : illegal use of type 'void'
e:\myprojects\第五章\10.cpp(35) : error C2373: 'showLarger' : redefinition; different type modifiers
e:\myprojects\第五章\10.cpp(35) : error C2059: syntax error : ')'
e:\myprojects\第五章\10.cpp(36) : error C2143: syntax error : missing ';' before '{'
e:\myprojects\第五章\10.cpp(36) : error C2447: missing function header (old-style formal list?)
执行 cl.exe 时出错. 10.obj - 1 error(s), 0 warning(s)
刚开始学习,什么都不懂!麻烦各位了!
2012年04月23日 14点04分 2
level 5
C风格字符串中S1和S2比较时好像不能直接比较吧,唔,没记错好像是要调用一个strcmy函数
strmpy(s1,s2),只有在C++语言中才可以直接比较吧。
2012年04月23日 14点04分 3
level 8
ssnhero 楼主
好像VC++6.0的头文件都必须是.h的,不加的话就出错!我发的是书上的原文来着,不知道为什么错啊!
2012年04月23日 14点04分 4
level 8
编译器不能识别string
你可以把前面改成
#include<string>
using namespace std;
这样应该就可以了,
2012年04月23日 15点04分 5
level 8
你最好把第一个也改了,#include<iostream> 如果你只用了这一个库的话,你就可以写
#incldue<iostream.h> 就不用写后面的 using namespace std; 了
2012年04月23日 15点04分 6
level 3
vc++6.0是不用加 “.h”的
2012年04月23日 15点04分 8
level 4
c++的头文件都是没后缀的
而带.h的都是c的,都是为了兼容c的
而 例如cmath则是为了说明新的c++头文件,但是用以前的c的头文件的内容
2012年04月23日 15点04分 9
level 8
ssnhero 楼主
[Love]学校太恶心了 我怀疑弄得是盗版书!错误这么多!搞定了,谢谢!!
2012年04月23日 15点04分 12
level 8
ssnhero 楼主
好的!以后养成这个好习惯!谢谢!![Yeah]
2012年04月23日 15点04分 13
level 8
ssnhero 楼主
虽然不懂你在说什么!!但是谢谢你来捧场![顶]
2012年04月23日 15点04分 14
level 8
ssnhero 楼主
嗯 加不加都行!不过看起来不加是主流吧?以后改过来![抖胸]
2012年04月23日 15点04分 16
level 8
ssnhero 楼主
嗯 明白了!刚去百度百科自己科普了一下!谢谢![Love]
2012年04月23日 16点04分 17
level 8
ssnhero 楼主
谢谢了!我回去好好研究下你给的这个!不过貌似还没看到类和继承派生什么的呢![揉脸]
2012年04月23日 16点04分 18
level 8
ssnhero 楼主
最后把改好的放出来!
#include<iostream>
#include<string>
using namespace std;
void showLarger(int n1,int n2);
void showLarger(float f1,float f2);
void showLarger(string s1,string s2);
void main()
{
int num1=50,num2=100;
float numA=1.1f,numB=9.9f;
string str1="Sunny day !";
string str2="Wonderful tonight !";
showLarger(num1,num2);
showLarger(numA,numB);
showLarger(str1,str2);
}
void showLarger(int n1,int n2)
{
if(n1==n2)
cout<<n1<<"equals"<<n2<<endl;
else if(n1>n2)
cout<<"Between "<<n1<<"and"<<n2<<"the larger one is "<<n1<<endl;
else
cout<<"Between "<<n1<<"and"<<n2<<"the larger one is "<<n2<<endl;
}
void showLarger(float f1,float f2)
{
if(f1==f2)
cout<<f1<<"equals"<<f2<<endl;
else if(f1>f2)
cout<<"Between "<<f1<<"and"<<f2<<"the larger one is "<<f1<<endl;
else
cout<<"Between "<<f1<<"and"<<f2<<"the larger one is "<<f2<<endl;
}
void showLarger(string s1,string s2)
{
if(s1==s2)
cout<<s1<<"equals"<<s2<<endl;
else if(s1>s2)
{
cout<<"Between "<<"\" "<<s1<<"\""<<endl;
cout<<" and"<<"\" "<<s2<<"\""<<endl;
cout<<" the larger one is "<<"\" "<<s1<<"\""<<endl;
}
else
{
cout<<"Between "<<"\" "<<s1<<"\""<<endl;
cout<<" and"<<"\" "<<s2<<"\""<<endl;
cout<<" the larger one is "<<"\" "<<s2<<"\""<<endl;
}
}
2012年04月23日 16点04分 20
level 8
ssnhero 楼主
[Love][Love][Love][Love][Love]太感谢了!好人啊!这两个程序我一定好好看看![口水]
2012年04月23日 16点04分 22
level 8
ssnhero 楼主
竟然是这样!好吧!那我争取早日脱白![88]
2012年04月24日 11点04分 23
1