求高手赐教
看c++ primer 第4版 上的附带的一段代码 为什么这段代码无法通过编译 我用 Visual C++ 6.0 编译器#include <string>
#include <iostream>
using std::cout; using std::endl;
using std::string;
char *cp = "Hiya"; // null-terminated array
char c_array[] = "World!!!!"; //null-terminated
char no_null[] = {'H', 'i'}; // not null-terminated
string s1(cp); // s1 == "Hiya"
string s2(c_array, 5); // s2 == "World"
string s3(c_array + 5, 4); // s3 == "!!!!"
string s4(no_null); // runtime error: no_null not null-terminated
string s5(no_null, 2); // ok: s5 == "Hi"
string s6(s1, 2); // s6 == "ya"
string s7(s1, 0, 2); // s7 == "Hi"
string s8(s1, 0, 8); // s8 == "Hiya"
int main()
{
cout << s1 << '\n' << s2 << '\n'
<< s3 << '\n' << s5 << '\n'
<< s6 << '\n' << s7 << endl;
{
string s1; // s1 is the empty string
string s2(5, 'a'); // s2 == "aaaaa"
string s3(s2); // s3 is a copy of s2
string s4(s3.begin(),
s3.begin() + s3.size() / 2); // s4 == "aa"
cout << s1 << '\n' << s2 << '\n'
<< s3 << '\n' << s4 << endl;
}
return 0;
}