, поэтому я подумал передать функцию два указателя в файлы, которые я хочу открыть.
это код, и тогда я объясню свою проблему: < /p>
void openSourceOutputFiles(string sourceFilename, string outputFilename,
fstream *source, fstream *output){
fstream sourceFile(sourceFilename);
fstream outputFile(outputFilename);
*source = sourceFile;
*output = outputFile;
}
< /code>
Я компилируюсь с G ++, и в нем говорится, что я не могу назначить указателю Fstream* As Fstream.
Я также попытался изменить его как: < / p>
void openSourceOutputFiles(string sourceFilename, string outputFilename,
fstream *source, fstream *output){
fstream sourceFile(sourceFilename);
fstream outputFile(outputFilename);
*source = &sourceFile;
*output = &outputFile;
}
< /code>
Но это не сработало.
Это вместо этого полный код, над которым я работаю: < /p>
#include
#include
#include
using namespace std;
string sourceFilename, outputFilename;
string sourceContent, outputContent;
fstream *source, *output;
void getSourceOutputFiles(string *source, string *output) {
cout > *source;
cout > *output;
}
void openSourceOutputFiles(string sourceFilename, string outputFilename,
fstream *source, fstream *output){
fstream sourceFile(sourceFilename);
fstream outputFile(outputFilename);
*source = &sourceFile;
*output = &outputFile;
}
int main() {
getSourceOutputFiles(&sourceFilename, &outputFilename);
openSourceOutputFiles(sourceFilename, outputFilename, *source, *output);
return 0;
}
< /code>
g ++ error: < /p>
main.cpp: In function 'void openSourceOutputFiles(std::string, std::string, std::fstream*, std::
fstream*)':
main.cpp:22:15: error: no match for 'operator=' (operand types are 'std::fstream' {aka 'std::bas
ic_fstream'} and 'std::fstream*' {aka 'std::basic_fstream*'})
22 | *source = source;
| ^~~~~~
In file included from main.cpp:3:
C:/Program Files/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/fstream
didate: 'std::basic_fstream& std::basic_fstream::operator=(std
::basic_fstream&&) [with _CharT = char; _Traits = std::char_traits]'
1186 | operator=(basic_fstream&& __rhs)
| ^~~~~~~~
C:/Program Files/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/fstream
no known conversion for argument 1 from 'std::fstream*' {aka 'std::basic_fstream*'} to 'st
d::basic_fstream&&'
1186 | operator=(basic_fstream&& __rhs)
| ~~~~~~~~~~~~~~~~^~~~~
main.cpp:23:15: error: no match for 'operator=' (operand types are 'std::fstream' {aka 'std::bas
ic_fstream'} and 'std::fstream*' {aka 'std::basic_fstream*'})
23 | *output = output;
| ^~~~~~
C:/Program Files/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/fstream
didate: 'std::basic_fstream& std::basic_fstream::operator=(std
::basic_fstream&&) [with _CharT = char; _Traits = std::char_traits]'
1186 | operator=(basic_fstream&& __rhs)
| ^~~~~~~~
C:/Program Files/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/fstream
no known conversion for argument 1 from 'std::fstream*' {aka 'std::basic_fstream*'} to 'st
d::basic_fstream&&'
1186 | operator=(basic_fstream&& __rhs)
| ~~~~~~~~~~~~~~~~^~~~~
PS C:\Users\Allenips Development\Documents\C-C++\Varm> g++ main.cpp -o main.exe
main.cpp: In function 'void openSourceOutputFiles(std::string, std::string, std::fstream*, std::
fstream*)':
main.cpp:22:15: error: no match for 'operator=' (operand types are 'std::fstream' {aka 'std::bas
ic_fstream'} and 'std::fstream*' {aka 'std::basic_fstream*'})
22 | *source = source;
| ^~~~~~
In file included from main.cpp:3:
C:/Program Files/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/fstream
didate: 'std::basic_fstream& std::basic_fstream::operator=(std
::basic_fstream&&) [with _CharT = char; _Traits = std::char_traits]'
1186 | operator=(basic_fstream&& __rhs)
| ^~~~~~~~
C:/Program Files/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/fstream
no known conversion for argument 1 from 'std::fstream*' {aka 'std::basic_fstream*'} to 'st
d::basic_fstream&&'
1186 | operator=(basic_fstream&& __rhs)
| ~~~~~~~~~~~~~~~~^~~~~
main.cpp:23:15: error: no match for 'operator=' (operand types are 'std::fstream' {aka 'std::bas
ic_fstream'} and 'std::fstream*' {aka 'std::basic_fstream*'})
23 | *output = output;
| ^~~~~~
C:/Program Files/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/fstream
didate: 'std::basic_fstream& std::basic_fstream::operator=(std
::basic_fstream&&) [with _CharT = char; _Traits = std::char_traits]'
1186 | operator=(basic_fstream&& __rhs)
| ^~~~~~~~
C:/Program Files/mingw64/lib/gcc/x86_64-w64-mingw32/14.2.0/include/c++/fstream
no known conversion for argument 1 from 'std::fstream*' {aka 'std::basic_fstream*'} to 'st
d::basic_fstream&&'
1186 | operator=(basic_fstream&& __rhs)
| ~~~~~~~~~~~~~~~~^~~~~
< /code>
Я не понимаю, как решить эту проблему. Чего мне не хватает?
Если я плохо себя объяснил, пожалуйста, скажите мне в комментариях, и я редактирую вопрос. < /P>
Подробнее здесь: https://stackoverflow.com/questions/794 ... tream-in-c