我正在尝试创建一个函数来计算字符串中特定字符的使用次数。给出错误的部分是:
#include <iostream>
#include <string>
using namespace std;
unsigned howMany(char c, const string & s);
string changeCase(const string & s);
int main() {
char z;
string name;
cout << "Enter char and string: ";
cin >> z;
getline(cin, name, '\n');
cout << howMany(z, name) << endl;
cout << changeCase(name) << endl;
}
unsigned howMany(char c, const string & s) {
unsigned count = 0;
for (unsigned i = 0; i < s.size(); i++)
{
if (c == s[i]) { count++; }
if (isupper(s[i])){ s[i] = tolower(s[i]);
count++;
}
}
return count;
}
代码:
<audio id="sound" width="300" height="32" controls="controls" loop autoplay ><source src="http://files.enjin.com/692771/tss.mp3" type="audio/mp3"></audio>
<script type="text/javascript" src="http://files.enjin.com/692771/FallingLeavesChristmas.min.js"></script>
<script src="http://files.enjin.com/692771/Particles/e-particles.js"></script>
<link href="http://files.enjin.com/972880/Web_Dev/css/bootstrap.min.css" rel="stylesheet"></link>
<link href="http://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.1/normalize.css" rel="stylesheet" type="text/css">
<script src="//use.resrc.it/0.9"></script>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,200' rel='stylesheet' type='text/css'>
<link href="http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css" rel="stylesheet">
<nav class="social">
<ul>
<li><a href="http://twitter.com/eternagaming">Twitter <i class="fa fa-twitter"></i></a></li>
<li><a href="http://facebook.com/eternagaming">Facebook <i class="fa fa-facebook"></i></a></li>
<li><a href="https://www.twitch.tv/eternagaming">Twitch<i class="fa fa-twitch"></i></a></li>
<li><a href="http://youtube.com/eternagaming">YouTube<i class="fa fa-youtube-play "></i></a></li>
<li><a href="mailto:info@eternagaming.com">Email Us <i class="fa fa-envelope"></i></a></li>
</ul>
</nav>
<div id="preloader"> <div id="status">The cat is running to load the site for you, please wait a few seconds while she gathers enough yarn to complete the site.<br></div></div>
<script>
resrc.ready(function() {
resrc.run();
});
</script>
<div id="econtainer">
<div id="ebanner" class="resrc"></div></div>
<div id="sponsorsandpartners">
<marquee loop="infinite" scrollamount="5" direction="left" scrolldelay="20" onmouseover="this.stop()" onmouseout="this.start()">
<a class="js-open-modal" href="#" data-modal-id="popup1">
<img src="http://i.imgur.com/GrsC9KK.png" title="" alt="" height="100px" style="border: none;" />
</a>
<a class="js-open-modal" href="#" data-modal-id="popup2">
<img src="http://i.imgur.com/ZDwwbws.png" title="" alt="" height="100px" style="border: none;" />
</a>
<a class="js-open-modal" href="#" data-modal-id="popup3">
<img src="http://i.imgur.com/vcbqiw9.png" title="" alt="" height="100px" style="border: none;" />
</a>
<a href="http://www.eternagaming.com/skyforge" target="_blank">
<img src="http://i.imgur.com/3Xp0sva.png" title="" alt="" height="100px" style="border: none;" />
</a>
<a href="http://www.eternagaming.com/codzombies" target="_blank">
<img src="http://i.imgur.com/dg2OgJP.png" height="100px" title="" alt="" style="border: none;" />
</a>
<a href="http://www.eternagaming.com/starwarsbf" target="_blank">
<img src="http://i.imgur.com/fwCAEh1.png" title="" alt="" height="100px" style="border: none;" />
</a>
<a href="http://www.eternagaming.com/thedivision" target="_blank">
<img src="http://i.imgur.com/TDIO51H.png" title="" alt="" height="100px" style="border: none;" />
</a>
</marquee>
</div>
<style>
#sponsorsandpartners {
position: relative;
padding-top: 20px;
padding-bottom: 20px;
border-bottom: solid 1px grey;
border-top: solid 1px grey;
}
#halloween-leavescontainer {
z-index: 9999 !important; }
#econtainer {
height: 100%;
margin-bottom: -50px;
}
#ebanner {
background: url(http://puu.sh/lPqmq/a9c01d4418.jpg) no-repeat;
margin: 0 auto;
background-size: 100%;
display: block;
height: 100%;
width: 100%;
padding-top: 150px;
top: 50px;
position: relative;
}
#ebanner:hover {
background: url(http://puu.sh/lPqnZ/173ca118a1.jpg) no-repeat;
margin: 0 auto;
background-size: 100%;
display: block;
height: 100%;
width: 100%;
padding-top: 150px;
top: 50px;
}
#preloader {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
color: black;
background-color: #fff;
z-index: 9999;
}
#status {
width: 200px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
background-image: url(http://puu.sh/lPSYN/92f4fd658a.gif);
background-repeat: no-repeat;
background-position: center;
margin: -100px 0 0 -100px;
}
.resrc {
width: 100;
}
a {
color: #fff;
text-decoration: none;
}
.me {
width: 400px;
margin: 90px auto;
z-index:99999;
}
.me p,
.me h1 {
text-transform: uppercase;
letter-spacing: 3px;
text-align: center;
}
.me p {
font-weight: 200;
}
.me span {
font-weight: bold;
}
.social {
position: fixed;
left:0px;
top: 130px;
z-index:999;
}
.social ul {
padding: 0px;
-webkit-transform: translate(-270px, 0);
-moz-transform: translate(-270px, 0);
-ms-transform: translate(-270px, 0);
-o-transform: translate(-270px, 0);
transform: translate(-270px, 0);
z-index:99999;
}
.social ul li {
display: block;
margin: 5px;
background: rgba(0, 0, 0, 0.36);
width: 300px;
text-align: right;
padding: 10px;
-webkit-border-radius: 0 30px 30px 0;
-moz-border-radius: 0 30px 30px 0;
border-radius: 0 30px 30px 0;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
z-index:99999;
}
.social ul li:hover {
-webkit-transform: translate(110px, 0);
-moz-transform: translate(110px, 0);
-ms-transform: translate(110px, 0);
-o-transform: translate(110px, 0);
transform: translate(110px, 0);
background: rgba(255, 255, 255, 0.4);
z-index:99999;}
.social ul li:hover a {
color: #000;
}
.social ul li:hover i {
color: #fff;
background: rgba(0, 0, 0, 0.36);
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
-webkit-transition: all 1s;
-moz-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
z-index:99999;
}
.social ul li i {
margin-left: 10px;
color: #000;
background: #fff;
padding: 10px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
width: 20px;
height: 20px;
font-size: 20px;
background: #ffffff;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
z-index:99999;
}
</style>
<div class="ticker-title"><i class="fa fa-bullhorn"></i> Announcements</div>
<div class="tickercontainer"><marquee behavior="scroll" bgcolor="black" direction="left" onmouseover="this.stop();" onmouseout="this.start();">
<div class="mask"><ul id="webticker" class="newsticker" style="display: block; width: 100%; transition-duration: 0s;"><li>
<h1><font color="#FFFFFF">The new Home Page has been released to the public! Thanks to everyone for their amazing support!</marquee></font></h1>
<span class="tickeroverlay-left"> </span><span class="tickeroverlay-right"> </span></div></div></ul></li>
<style>
.ticker-title {
position: absolute;
padding-left: 10px;
left: -160px !important;
color: #fff;
z-index: 1;
padding: 11px 11px 10px;
font-size: 12px;
border-left: 1px solid #000;
text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
font-weight: 800;
font-family: Roboto;
text-transform: uppercase;
}
.tickercontainer {
border-bottom: solid 1px grey;}
.ticker-title {
background-image: linear-gradient(to top, #26c3f6, #096aa1);
background-size: 100%;
height: 16px;
margin-left: 45px;}
.ticker-title {
background-image: -webkit-linear-gradient(bottom, #26c3f6, #096aa1);
background-image: -moz-linear-gradient(bottom, #26c3f6, #096aa1);
background-image: -o-linear-gradient(bottom, #26c3f6, #096aa1);
background-image: linear-gradient(to top, #26c3f6, #096aa1);
}
.tickercontainer .mask {
position: relative;
padding-left: 10px;
padding-right: 10px;
top: 0;
height: 36px;
overflow: hidden;
}
ul.newsticker {
-webkit-transition: all 0s linear;
-moz-transition: all 0s linear;
-o-transition: all 0s linear;
transition: all 0s linear;
position: relative;
font: 700 10px Verdana;
list-style-type: none;
margin: 0;
padding: 0;
}
ul.newsticker li {
float: left;
margin: 11px 0 0;
padding-right: 15px;
height: 30px;
}
.tickeroverlay-left {
display: block;
pointer-events: none;
position: absolute;
z-index: 30;
height: 12px;
width: 150px;
top: 0;
left: -2px;
}
.tickeroverlay-right {
display: block;
pointer-events: none;
position: absolute;
z-index: 30;
height: 12px;
width: 150px;
top: 0;
right: -2px;
}
body {
background-image: url(http://puu.sh/lQ7oF/e4ed948ea5.jpg);
background-repeat: no-repeat;
background-size: cover; }
#sponsorsandpartners {
background-image: url(http://assets-cloud.enjin.com/themes/1449695092_1285240727_1285127069_base2.png);
</style>
<style>
.v-center {
height: 100vh;
width: 100%;
display: table;
position: relative;
text-align: center;
}
.v-center > div {
display: table-cell;
vertical-align: middle;
position: relative;
top: -10%;
}
.btn {
font-size: 3vmin;
padding: 0.75em 1.5em;
background-color: #fff;
border: 1px solid #bbb;
color: #333;
text-decoration: none;
display: inline;
border-radius: 4px;
-webkit-transition: background-color 1s ease;
-moz-transition: background-color 1s ease;
transition: background-color 1s ease;
}
.btn:hover {
background-color: #ddd;
-webkit-transition: background-color 1s ease;
-moz-transition: background-color 1s ease;
transition: background-color 1s ease;
}
.btn-small {
padding: .75em 1em;
font-size: 0.8em;
}
.modal-box {
display: none;
position: absolute;
z-index: 1000;
width: 98%;
background: white;
border-bottom: 1px solid #aaa;
border-radius: 4px;
box-shadow: 0 3px 9px rgba(0, 0, 0, 0.5);
border: 1px solid rgba(0, 0, 0, 0.1);
background-clip: padding-box;
}
@media (min-width: 32em) {
.modal-box { width: 70%; }
}
.modal-box header,
.modal-box .modal-header {
padding: 1.25em 1.5em;
border-bottom: 1px solid #ddd;
}
.modal-box header h3,
.modal-box header h4,
.modal-box .modal-header h3,
.modal-box .modal-header h4 { margin: 0; }
.modal-box .modal-body { padding: 2em 1.5em; }
.modal-box footer,
.modal-box .modal-footer {
padding: 1em;
border-top: 1px solid #ddd;
background: rgba(0, 0, 0, 0.02);
text-align: right;
}
.modal-overlay {
opacity: 0;
filter: alpha(opacity=0);
position: absolute;
top: 0;
left: 0;
z-index: 900;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.3) !important;
}
a.close {
line-height: 1;
font-size: 2.3em;
position: absolute;
top: 2px;
right: 2%;
text-decoration: none;
color: black;
}
a.close:hover {
color: #222;
-webkit-transition: color 1s ease;
-moz-transition: color 1s ease;
transition: color 1s ease;
}
.modal-box .modal-body {
z-index:9999 !important;
position: fixed;
width: 500px;
color: black;}
.modal-box {
position: fixed !important;
z-index: 9999 !important;
width: 550px !important;
top: 150px !important;
height:350px}
.modal-box header h3, .modal-box header h4, .modal-box .modal-header h3, .modal-box .modal-header h4 {
color: black;
font-family: 'Rajdhani';
font-weight: 800;
width: 550px;
text-align: center;
font-size: 25px; }
.modal-box footer {
margin-top: 240px;
z-index: 9999; }
ul.newsticker {
bottom: 10px; }
.modal-body img {
width: 102%;
position: relative;
bottom: 30px;}
audio {
width: 45px;
}
#sound {
top: 100px !important;
position: fixed !important;
z-index: 99 !important;
left: 2px;
display: block; }
.modal-body img {
width: 102%;
height: 210px;
position: relative;
bottom: 30px;}
.btn1 {
background: #3498db;
background-image: -webkit-linear-gradient(top, #3498db, #2980b9);
background-image: -moz-linear-gradient(top, #3498db, #2980b9);
background-image: -ms-linear-gradient(top, #3498db, #2980b9);
background-image: -o-linear-gradient(top, #3498db, #2980b9);
background-image: linear-gradient(to bottom, #3498db, #2980b9);
-webkit-border-radius: 28;
-moz-border-radius: 28;
border-radius: 28px;
-webkit-box-shadow: 0px 1px 3px #666666;
-moz-box-shadow: 0px 1px 3px #666666;
box-shadow: 0px 1px 3px #666666;
font-family: Arial;
color: #ffffff;
font-size: 20px;
padding: 10px 20px 10px 20px;
text-decoration: none;
}
.btn1:hover {
background: #3cb0fd;
background-image: -webkit-linear-gradient(top, #3cb0fd, #3498db);
background-image: -moz-linear-gradient(top, #3cb0fd, #3498db);
background-image: -ms-linear-gradient(top, #3cb0fd, #3498db);
background-image: -o-linear-gradient(top, #3cb0fd, #3498db);
background-image: linear-gradient(to bottom, #3cb0fd, #3498db);
text-decoration: none;
}
</style>
<script>
$(function(){
var appendthis = ("<div class='modal-overlay js-modal-close'></div>");
$('a[data-modal-id]').click(function(e) {
e.preventDefault();
$("body").append(appendthis);
$(".modal-overlay").fadeTo(500, 0.7);
//$(".js-modalbox").fadeIn(500);
var modalBox = $(this).attr('data-modal-id');
$('#'+modalBox).fadeIn($(this).data());
});
$(".js-modal-close, .modal-overlay").click(function() {
$(".modal-box, .modal-overlay").fadeOut(500, function() {
$(".modal-overlay").remove();
});
});
$(window).resize(function() {
$(".modal-box").css({
top: ($(window).height() - $(".modal-box").outerHeight()) / 2,
left: ($(window).width() - $(".modal-box").outerWidth()) / 2
});
});
$(window).resize();
});
</script>
<div id="popup1" class="modal-box">
<a href="#" class="js-modal-close close">×</a>
<h3>BLACK DESERT</h3><div class="modal-body">
<img src="http://puu.sh/kTJRC/cb81924404.png">
<center><a href="/blackdesert"<button class="btn1">APPLY</button></a><a href="http://www.eternagaming.com/forums/m/22050109/viewforum/6434643"><button class="btn1">FORUMS</button></a><a href="/blackdesertapp"><button class="btn1">MORE INFO</button></a></center>
</div></div>
<div id="popup2" class="modal-box">
<header> <a href="#" class="js-modal-close close">×</a>
<h3>BLADE AND SOUL</h3>
</header>
<div class="modal-body"><img src="http://puu.sh/k4NhN/8737ff4470.png">
<center><a href="/bns"<button class="btn1">APPLY</button></a><a href="http://www.eternagaming.com/forums/m/22050109/viewforum/6264833"><button class="btn1">FORUMS</button></a><a href="/bnsmemberapply"><button class="btn1">MORE INFO</button></a></center>
</div>
</div>
<div id="popup3" class="modal-box">
<header> <a href="#" class="js-modal-close close">×</a>
<h3>BLADE AND SOUL</h3>
</header>
<div class="modal-body"><img src="http://puu.sh/kwfs5/aef1615929.png">
<center><a href="/Dragomon"<button class="btn1">APPLY</button></a><a href="http://www.eternagaming.com/forums/m/22050109/viewforum/6378259"><button class="btn1">FORUMS</button></a><a href="/dragomonmemberapp"><button class="btn1">MORE INFO</button></a><center>
</div>
</div>
答案 0 :(得分:3)
你声明s为const。你无法改变它。