ファイル名とテキストを入力してファイルに書き込むように何かを作成しようとしていますが、コンパイルしようとすると次のように表示されます。
files.cc: In function ‘int main()’:
files.cc:11: error: ambiguous overload for ‘operator>>’ in ‘std::cin >> filetoopen’
/usr/include/c++/4.2.1/istream:131: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
/usr/include/c++/4.2.1/istream:135: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
/usr/include/c++/4.2.1/istream:142: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
/usr/include/c++/4.2.1/istream:250: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
files.cc:14: error: no match for ‘operator>>’ in ‘std::cout >> text’
files.cc:16: error: conversion from ‘std::fstream’ to non-scalar type ‘std::ofstream’ requested
files.cc: In function ‘char* openfile(std::fstream, char*)’:
files.cc:21: error: no matching function for call to ‘std::basic_fstream<char, std::char_traits<char> >::open()’
/usr/include/c++/4.2.1/fstream:780: note: candidates are: void std::basic_fstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
#include <iostream>
#include <fstream>
using namespace std;
char* openfile(ofstream file, char* words);
int main()
{
fstream filetoopen;
char* text;
cout << "Enter the name of a file to write to." << endl;
cin >> filetoopen;
cout << "Now write somthing to the file." << endl;
cin >> text;
openfile(filetoopen, text);
}
char * openfile (fstream file, char* words)
{
file.open();
file << words << endl;
file.close();
return words;
}
私はC++に非常に慣れていないため、これが何を意味するのかわかりません。また、関数が配列を返すようにする方法がわからないので、ちょっと推測しました。誰でも助けることができますか?