开发者

Opening a file in C++

开发者 https://www.devze.com 2023-02-19 19:35 出处:网络
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.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消