小编Dom*_*Dom的帖子

字符串C++中的字符交换

我不知道为什么这不起作用,我需要交换两个字符作为a和b输入,它编译,但所有的字符被替换为输入为b的字符,任何建议?

while (n != exist)
{
    cout<<"What is the letter you want to swap?"<<endl;
    cin>>a;             
    cout<<"What is the letter you want to swap it with?"<<endl;
    cin>>b;
    if (inFile.is_open())
    {
        while (inFile.good())
        {   
            inFile.get(c);
            if( c = a )
            {
                outFile<< b;
            }
            else if (c = b)
            {
                outFile<< a;
            }
            else
            {
                outFile<< c;
            }                               
        }                           
    }
    else
    {
        cout<<"Please run the decrypt."<<endl;
    }
    cout<<"Another letter? <n> to stop swapping"<<endl;
    cin>>n;
}               
Run Code Online (Sandbox Code Playgroud)

c++ swap replace ifstream

0
推荐指数
4
解决办法
1439
查看次数

标签 统计

c++ ×1

ifstream ×1

replace ×1

swap ×1