Note that there are some explanatory texts on larger screens.

plurals
  1. POambiguous overload for ‘operator>>’ in ‘std::cin >>
    text
    copied!<p>I'm trying to make something so you enter a file name and then text to write to the file but when I try to compile it it says this:</p> <pre><code>files.cc: In function ‘int main()’: files.cc:11: error: ambiguous overload for ‘operator&gt;&gt;’ in ‘std::cin &gt;&gt; filetoopen’ /usr/include/c++/4.2.1/istream:131: note: candidates are: std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::basic_istream&lt;_CharT, _Traits&gt;::operator&gt;&gt;(std::basic_istream&lt;_CharT, _Traits&gt;&amp; (*)(std::basic_istream&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;] &lt;near match&gt; /usr/include/c++/4.2.1/istream:135: note: std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::basic_istream&lt;_CharT, _Traits&gt;::operator&gt;&gt;(std::basic_ios&lt;_CharT, _Traits&gt;&amp; (*)(std::basic_ios&lt;_CharT, _Traits&gt;&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;] &lt;near match&gt; /usr/include/c++/4.2.1/istream:142: note: std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::basic_istream&lt;_CharT, _Traits&gt;::operator&gt;&gt;(std::ios_base&amp; (*)(std::ios_base&amp;)) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;] &lt;near match&gt; /usr/include/c++/4.2.1/istream:250: note: std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::basic_istream&lt;_CharT, _Traits&gt;::operator&gt;&gt;(std::basic_streambuf&lt;_CharT, _Traits&gt;*) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;] &lt;near match&gt; files.cc:14: error: no match for ‘operator&gt;&gt;’ in ‘std::cout &gt;&gt; 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&lt;char, std::char_traits&lt;char&gt; &gt;::open()’ /usr/include/c++/4.2.1/fstream:780: note: candidates are: void std::basic_fstream&lt;_CharT, _Traits&gt;::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;] </code></pre> <p><sup></sup></p> <pre><code>#include &lt;iostream&gt; #include &lt;fstream&gt; using namespace std; char* openfile(ofstream file, char* words); int main() { fstream filetoopen; char* text; cout &lt;&lt; "Enter the name of a file to write to." &lt;&lt; endl; cin &gt;&gt; filetoopen; cout &lt;&lt; "Now write somthing to the file." &lt;&lt; endl; cin &gt;&gt; text; openfile(filetoopen, text); } char * openfile (fstream file, char* words) { file.open(); file &lt;&lt; words &lt;&lt; endl; file.close(); return words; } </code></pre> <p>I am very new to C++ an have no idea what any of this means. Also I'm not sure if how to make a function return an array so I kinda guessed. Can any one help?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload