私は、関数replacef(char型のmは)(charとして初期化)の数で、文字A/Aを交換したいです。しかし、forループで関数を呼び出すと、quota.marksを除いて "Alabama"などと書くと、プログラムは文字列をそのまま返します。この機能が正しく動作するように、どのように文字を渡すことができますか?文字列のcharをC++の関数に渡しますか?私のプログラムで
#include <iostream>
#include <string>
using namespace std;
string n;
void replacef(char m)
{
switch (m)
{
case 'A':
case 'a':
m='1';
}
}
int main()
{
cin>>n;
for(int i=0; i<n.length(); i++)
{
replacef(n[i]);//Replace the current char in the string
}
cout<<n<<endl;
}
S/'無効replacef(char型のM)'/'無効replacef(CHAR&Mコメント) ' – user0042