| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 495 人关注过本帖
标题:c++疑惑
只看楼主 加入收藏
魔鬼之子
Rank: 1
来 自:地狱之都
等 级:新手上路
帖 子:100
专家分:0
注 册:2007-9-22
结帖率:71.43%
收藏
 问题点数:0 回复次数:2 
c++疑惑
# include <iostream.h>
# include <string.h>

template <class T>
T Max(T a,T b){
    return (a>b)?a:b;
}

void main(){
    int ix=12,iy=13;
    double dx=9.9,dy=7.8;
    string sx("abv"),sy("uid");
   
    cout<<"Type int:"<<Max(ix,iy)<<endl;
    cout<<"Type double:"<<Max(dx,dy)<<endl;
    cout<<"Type string:"<<Max(sx,sy)<<endl;
}

以上是源程序,可是在编译时却出现以下错误:

Compiling...
temexample.cpp
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(12) : error C2065: 'string' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(12) : error C2146: syntax error : missing ';' before identifier 'sx'
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(12) : error C2065: 'sx' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(12) : error C2065: 'sy' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(14) : error C2065: 'cout' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(14) : error C2297: '<<' : illegal, right operand has type 'char [10]'
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(14) : error C2065: 'endl' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(15) : error C2297: '<<' : illegal, right operand has type 'char [13]'
c:\program files\microsoft visual studio\myprojects\first\temexample.cpp(16) : error C2297: '<<' : illegal, right operand has type 'char [13]'
执行 cl.exe 时出错.

First.exe - 1 error(s), 0 warning(s)
万望指教!
搜索更多相关主题的帖子: microsoft include double return visual 
2009-09-23 21:29
gz81
Rank: 5Rank: 5
等 级:职业侠客
帖 子:137
专家分:369
注 册:2008-5-1
收藏
得分:0 
# include <iostream>
# include <string>
using namespace std;
 
template <class T>
T Max(T a,T b){
    return (a>b)?a:b;
}
 
int main(){
    int ix=12,iy=13;
    double dx=9.9,dy=7.8;
    string sx("abv"),sy("uid");
     
    cout<<"Type int:"<<Max(ix,iy)<<endl;
    cout<<"Type double:"<<Max(dx,dy)<<endl;
    cout<<"Type string:"<<Max(sx,sy)<<endl;
}



运行结果:


Type int:13
Type double:9.9
Type string:uid
请按任意键继续. . .

我的空间:http://student./space.php?uid=116706
2009-09-23 21:34
shl305
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:36
专家分:121
注 册:2009-3-13
收藏
得分:0 
string sx("abv"),sy("uid");改为
std::string sx("abv"),sy("uid");
2009-09-23 21:44
快速回复:c++疑惑
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.120162 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved