私はC++とプログラミング全般に比較的慣れていないので、私の間違いはかなり単純なものだと思います。とにかく、私は.txtファイルからのDNA配列のスキャンに取り組んでおり、ユーザーがコマンドラインからデータファイルの名前を指定できるようにプログラムしようとしています。参照用に関数全体を含めましたが、ファイルを実際に開くことができなかったという特定の問題が発生し、プログラムは常に「ファイルを開くことができません」というメッセージを返します。私が問題を抱えている部分(私は思う)は最後のforループですが、参照用に関数全体を含めました。
int dataimport (int argc, char* argv[]){
vector<string> mutationfiles (argc -1); //mutationfiles: holds output file names
vector<string> filenames (argc - 1); //filenames: holds input file names
if (argc > 1){
for ( int i = 1; i < argc; ++i){
string inputstring = argv[i]; //filename input by user
filenames[i-1] = inputstring; //store input filename in vector
stringstream out;
out << inputstring << "_mutdata.txt"; //append _mutdata.txt to input file names
mutationfiles[i-1] = (out.str()); //store as output file name
inputstring.clear(); //clear temp string
}
}
else{
cout << "Error: Enter file names to be scanned" << endl;
system("PAUSE");
return EXIT_FAILURE;
}
for(int repeat = 0; repeat < argc; ++repeat){
ifstream myfile; //open input file
myfile.open (filenames[repeat].c_str());
ofstream myfile2; //open output file
myfile2.open (mutationfiles[repeat].c_str());
string all_lines;
if (myfile.is_open()){
while ( myfile.good() ){ //scan data
getline (myfile,all_lines,'\0');
}
myfile.close(); //close infile
}
else{ //error message
cout << "Unable to open file\n";
system("PAUSE");
return EXIT_FAILURE;
}
}
}
あなたが必要とする追加情報や私が自分自身をより良く助けることができるように私が研究すべき何かがあるかどうか私に知らせてください!