所以这段代码只是我一直在搞乱的东西,但我似乎无法让它正常工作。switch 语句在完成第一个 case 后不会继续循环。我只是想让它基本上改变单词中的字母。我不太确定,如何解决它。任何帮助,将不胜感激。
这一直告诉我我需要更多的词,所以我只是随意写,请不要介意这些词,它们只是占位符,使系统不那么生气,因为我将我的问题总结为三个句子。
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
using namespace std;
int main()
{
char ans;
char fileName[50];
string inp;
int length;
ifstream inpFile;
ofstream outFile("output.txt");
do{
cout << "";
cin.getline(fileName, 50);
inpFile.open(fileName);
if(!inpFile.is_open()){
exit(EXIT_FAILURE);
}
string word;
char enc;
char temp;
length = word.length();
char * cstr = new char [length + 1];
strcpy(cstr, word.c_str());
for(int i = 0; i < length; i++){
switch(cstr[i]){
case 'A':{
temp = cstr[i];
temp = '0';
enc = temp;
break;
}
case 'a':{
temp = cstr[i];
temp = '1';
enc = temp;
break;
}
}
cout << "test1";
}
cout << "Test2";
delete[] cstr;
}while(ans == 'Y' || ans == 'y');
cout << "Test3";
}
您打开文件,但从未从中读取任何内容。您的变量 word 将始终为空,因此长度将为 0。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句