C++中关于string变量

来源:百度知道 编辑:UC知道 时间:2024/06/14 12:49:58
程序开头为:
#include <iostream>
using namespace std;
定义string变量不出错,
但开头为:
#include <iostream.h>
定义string变量出错,
我想问在第二种情况下怎么才能用string变量?是不是要加什么头文件?
问题有点错误,
应该是
第一个程序开头为
#include <iostream>
#include <string>
using namespace std;
第一个程序开头为
#include <iostream.h>
#include <string.h>

问题一样?
谢谢回答。

两种方法:
第一种:#include<string.h>
string s;
第二种:#include<string>
using namespace std;
string s;

其实是一样的但是由于编译器版本的问题可能不识别 常用的还是using namespace std;

你可以看一下c++编程思想第33页,上面说的很详细
但是,你只要知道一种对的就可以,不能执行的,肯定是错误的。