关于c里面的string.h

来源:百度知道 编辑:UC知道 时间:2024/05/14 04:37:59
/****test.c*****/
#include <stdio.h>
#include <string.h>
void main()
{
string str;
str = "hello!";
printf("%s", str);
}

/***test.cpp**/
#include <iostream>
#include <string.h>
using namespace std;
void main()
{
string str = "hello";
cout << str << endl;
}

初学c/c++,请帮忙指教为什么前面两个程序方法都有错

//string.h 是C的头文件,里面没有定义string
//C++头文件string定义了,并且不能用于c
//test.cpp
#include <iostream>
#include <string>
using namespace std;
void main()
{
string str = "hello";
cout << str << endl;
}