一个简单C++例子?

来源:百度知道 编辑:UC知道 时间:2024/06/20 18:25:15
这是程序代码:
#include <iostream.h>
#include <string.h>
#include "stdio.h"
void main()
{
string name="Niels Stroustrup";
string s=name.substr(6,10);
name.replace(0,5,"Nicholas");
printf("name:%s\n",name.c_str());
}
|
|
|
|这是程序出错提示:
--------------------Configuration: A_TEST - Win32 Debug--------------------
Compiling...
temp.cpp
E:\MATE\VC\A_TEST\temp.cpp(6) : error C2065: 'string' : undeclared identifier
E:\MATE\VC\A_TEST\temp.cpp(6) : error C2146: syntax error : missing ';' before identifier 'name'
E:\MATE\VC\A_TEST\temp.cpp(6) : error C2065: 'name' : undeclared identifier
E:\MATE\VC\A_TEST\temp.cpp(6) : error C2440: '=' : cannot convert from 'char [17]' to 'int'
This conversion requires a reinterp

#include <iostream>
#include <sstream>
#include <string>
#include <cstdio>
using namespace std;
int main()
{
string name="Niels Stroustrup";
string s=name.substr(6,10);
name.replace(0,5,"Nicholas");
printf("name:%s\n",name.c_str());
}
试试

在所有头文件后面加上一句
using namespace std;

name是什么数据类型,是个类么?,还有那种用法吗,能给它直接那样赋值?我怎么不知道,

呵呵C++......呵呵string型......你真厉害......

能把stdio.h发来吗?