首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

几行小程序的异常。

2012-05-29 
求助 几行小程序的错误。。。。。。。。。。。。。。。。。。。。。。。#include string.h#include iostream.husing namespace

求助 几行小程序的错误。。。。。。。。。。。。。。。。。。。。。。。
#include <string.h>
#include <iostream.h>
using namespace std;

int main()
{
string string1,string2,string3,temp;

cout<<"please input three strings:";

cin>>string1>>string2>>string3;

if(string2>string3)
{
temp=string2;
string2=string3;
string3=temp;
}

if(string1<=string2) 


cout<<string1<<" "<<string2<<" "<<string3<<endl;

else if(string1<=string3) 
cout<<string2<<" "<<string1<<" "<<string3<<endl;

else 
cout<<string2<<" "<<string3<<" "<<string1<<endl;

return 0;
}






--------------------Configuration: 110 - Win32 Debug--------------------
Compiling...
11.cpp
F:\soft\0010\110\11.cpp(4) : error C2871: 'std' : does not exist or is not a namespace
F:\soft\0010\110\11.cpp(8) : error C2065: 'string' : undeclared identifier
F:\soft\0010\110\11.cpp(8) : error C2146: syntax error : missing ';' before identifier 'string1'
F:\soft\0010\110\11.cpp(8) : error C2065: 'string1' : undeclared identifier
F:\soft\0010\110\11.cpp(8) : error C2065: 'string2' : undeclared identifier
F:\soft\0010\110\11.cpp(8) : error C2065: 'string3' : undeclared identifier
F:\soft\0010\110\11.cpp(8) : error C2065: 'temp' : undeclared identifier
执行 cl.exe 时出错.

11.obj - 1 error(s), 0 warning(s)






请问大侠们
如何修改呢?

[解决办法]
#include <string>
#include <iostream>
using namespace std;

[解决办法]

探讨
#include <string>
#include <iostream>
using namespace std;

[解决办法]
珍惜生命,远离vc6.0
[解决办法]
探讨
引用:
#include <string>
#include <iostream>
using namespace std;
就是这个

[解决办法]
探讨
引用:
引用:
#include <string>
#include <iostream>
using namespace std;
就是这个

要么用.h
要么用 using namespace std

[解决办法]
探讨
引用:
引用:
#include <string>
#include <iostream>
using namespace std;
就是这个

要么用.h
要么用 using namespace std

[解决办法]
#include <string.h>
#include <iostream.h>
using namespace std;
 
/////////////////////////
你如果使用老式的头文件,那么就不能用新式的
名称空间。两者不能混用的。
可以这样:
#include <string.h>
#include <iostream.h>
这样写是老式的写法。

在C++中,她完全兼容C,所以C的头文件,在C++中都可以用,
不过建议使用新式的头文件,可以这样写:

#include <cstring>
#include <iostream>
using namespace std;

//
要使用新式的头文件,只要把.h去掉,然后在前面加个C,然后记得要用上
名称空间:using namespace std;
[解决办法]
+1
探讨

#include <string>
#include <iostream>
using namespace std;


[解决办法]
把.h去了吧
[解决办法]
在VC6下面可以
#include <string>
#include <iostream.h>
在VS2005及以上则
#include <string>
#include <iostream>
using namespace std;


[解决办法]
7楼正解!! vc6下的头文件 是c++的头文件不用.h的 string.h是标准c的头文件 你这里没用到标准c的东西 所以不用 #include “string.h” 而且在vc6下 引入标准c的头文件是 #include “c***” 在标准c文件名前面加上c表示vc下引入的c的头文件 
#include ”cstring“
#include ”iostream"
using namespace std;
如不想用using namespace std; 可用std::cout。。。。
[解决办法]
楼上几个都说出了答案了
[解决办法]
探讨
珍惜生命,远离vc6.0

[解决办法]
探讨

珍惜生命,远离vc6.0

[解决办法]
探讨

#include <string>
#include <iostream>
using namespace std;

[解决办法]
#include <string>
#include <iostream>
using namespace std;

[解决办法]
探讨

珍惜生命,远离vc6.0

[解决办法]
6.0有点太早了。。。现在至少得用2005吧
[解决办法]
路过。。求分
[解决办法]
头文件去掉.h
#include <iostream>
#include <string>
using namespace std;

这一定要记住。
特别是和cout结合使用时,如果引用头文件时,加入头文件也会出问题的。
[解决办法]
(路过。。求分)++;
[解决办法]
他们都说了,我就不罗嗦了
[解决办法]
他们都说了,我就不罗嗦了
(路过。。求分)++;
[解决办法]
探讨
引用:
#include <string>
#include <iostream>
using namespace std;
就是这个

[解决办法]
字符串的输入,最好是用getline()吧,cin见不得空格,
[解决办法]
#include <string>
#include <iostream>
using namespace std;

[解决办法]
问题解决了,楼主结贴吧!
远离vc,生命珍惜!
最近用的CB!
[解决办法]
学好一门语言的方法,就是用这门语言。

热点排行