I am trying to open a file stored on my c drive with name test.txt
.I am getting a lot of errors.I am new to filing in C++.Please help me out thanks.
// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
ofstream mystream;
mystream.open("C:\\tes开发者_JS百科t",ios::in||ios::out);
/*Check if the file is opened properly*/
return 0;
}
This
mystream.open("C:\\test",ios::in || ios::out);
should be
mystream.open("C:\\test",ios::in | ios::out);
You are using the logical OR operator (||
) instead of the bitwise OR operator (|
). The former returns a boolean value, while the latter returns the bitwise OR of the two values.
You probably also want to fully qualify the filename. For example:
mystream.open("C:\\test.txt", ios::in | ios::out);
精彩评论