#include <iostream>
using namespace std;
int main()
{
cout << 'a' << endl;
cout << 'b' << endl;
cout << 'c' << endl;
cin.get();
return 0;
}
输出的是字符,并不是数字。
#include <iostream>
#include <string>
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());
cin.get();
return 0;
}
上例中:
substr是string的一个方法是获取从下标为6开始的十个字符。
replace是string一个方法是替换指定范围的字符,替换的字符串长度和被替换范围的字符长度不一定要要相等。
string 转化为C风格的字符的方法为string::c_str();
#include <iostream>
#include <string>
using namespace std;
int main()
{
double i;
cin >> i;
cin.get();
return 0;
}
上例中,可以输入12.34e5代表的数字为