练习3.6
#include "stdafx.h"
#include<iostream>
#include<string>
#include "stdafx.h"
using namespace::std;
int main()
{
string str("some string!!!!");
for (auto c : str)
{
c = 'x';
cout << c ;
}
system("pause");
return 0;
}
练习3.8
#include "stdafx.h"
#include<iostream>
#include<string>
#include "stdafx.h"
using namespace::std;
int main()
{
string str("some string!!!!");
decltype(str.size()) p = 0;
while (str[p])
{
str[p] = 'x';
++p;
}
cout << str << endl;
system("pause");
return 0;
}
用for循环写
#include "stdafx.h"
#include<iostream>
#include<string>
#include "stdafx.h"
using namespace::std;
int main()
{
string str("some string!!!!");
decltype(str.size()) p = 0;
for(;str[p] != NULL;++p)
{
str[p] = 'x';
}
cout << str << endl;
system("pause");
return 0;
}
练习3.9
string s;
cout << s[0] << endl;
不合法数组没有初始化。
练习3.10
#include "stdafx.h"
#include<iostream>
#include<string>
#include "stdafx.h"
using namespace::std;
int main()
{
string str;
getline(cin, str);
for(decltype(str.size()) p = 0; str[p]!= NULL;++p)
{
if (!ispunct(str[p]))
{
cout << str[p];
}
}
cout << endl;
system("pause");
return 0;
}
练习3.11
合法 const char &