Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何打印文件的内容?C++;文件流 我使用FStand和C++,我希望我的程序是打印出我的.txt文件的内容。这可能很简单,但我在网上看过很多东西,却找不到任何对我有帮助的东西。我该怎么做?以下是我目前掌握的代码: #include <iostream> #include <fstream> using namespace std; int main() { string output; ifstream myfile; ofstream myfile2; string STRING; myfile.open ("/Volumes/LFARLEIGH/Lucas.txt"); myfile2 << "Lucas, It Worked"; myfile >> STRING; cout << STRING << endl; myfile.close(); return 0; } #包括 #包括 使用名称空间std; int main(){ 字符串输出; ifstreammyfile; 流myfile2; 字符串字符串; myfile.open(“/Volumes/LFARLEIGH/Lucas.txt”); myfile2>字符串; 当这个功能已经在标准C++库中实现时,没有理由重新发明轮子。 #include <iostream> #include <fstream> int main() { std::ifstream f("file.txt"); if (f.is_open()) std::cout << f.rdbuf(); } #包括 #包括 int main() { std::ifstream f(“file.txt”); 如果(f.是开着的()) std::cout#包括 #包括 int main() { 字符串名; std::ifstream数据文件(“file.txt”); 而(!dataFile.fail()&&!dataFile.eof()) { 数据文件>>名称; cout_C++_Iostream_Fstream - Fatal编程技术网 字符串; 当这个功能已经在标准C++库中实现时,没有理由重新发明轮子。 #include <iostream> #include <fstream> int main() { std::ifstream f("file.txt"); if (f.is_open()) std::cout << f.rdbuf(); } #包括 #包括 int main() { std::ifstream f(“file.txt”); 如果(f.是开着的()) std::cout#包括 #包括 int main() { 字符串名; std::ifstream数据文件(“file.txt”); 而(!dataFile.fail()&&!dataFile.eof()) { 数据文件>>名称; cout,c++,iostream,fstream,C++,Iostream,Fstream" /> 字符串; 当这个功能已经在标准C++库中实现时,没有理由重新发明轮子。 #include <iostream> #include <fstream> int main() { std::ifstream f("file.txt"); if (f.is_open()) std::cout << f.rdbuf(); } #包括 #包括 int main() { std::ifstream f(“file.txt”); 如果(f.是开着的()) std::cout#包括 #包括 int main() { 字符串名; std::ifstream数据文件(“file.txt”); 而(!dataFile.fail()&&!dataFile.eof()) { 数据文件>>名称; cout,c++,iostream,fstream,C++,Iostream,Fstream" />

如何打印文件的内容?C++;文件流 我使用FStand和C++,我希望我的程序是打印出我的.txt文件的内容。这可能很简单,但我在网上看过很多东西,却找不到任何对我有帮助的东西。我该怎么做?以下是我目前掌握的代码: #include <iostream> #include <fstream> using namespace std; int main() { string output; ifstream myfile; ofstream myfile2; string STRING; myfile.open ("/Volumes/LFARLEIGH/Lucas.txt"); myfile2 << "Lucas, It Worked"; myfile >> STRING; cout << STRING << endl; myfile.close(); return 0; } #包括 #包括 使用名称空间std; int main(){ 字符串输出; ifstreammyfile; 流myfile2; 字符串字符串; myfile.open(“/Volumes/LFARLEIGH/Lucas.txt”); myfile2>字符串; 当这个功能已经在标准C++库中实现时,没有理由重新发明轮子。 #include <iostream> #include <fstream> int main() { std::ifstream f("file.txt"); if (f.is_open()) std::cout << f.rdbuf(); } #包括 #包括 int main() { std::ifstream f(“file.txt”); 如果(f.是开着的()) std::cout#包括 #包括 int main() { 字符串名; std::ifstream数据文件(“file.txt”); 而(!dataFile.fail()&&!dataFile.eof()) { 数据文件>>名称; cout

如何打印文件的内容?C++;文件流 我使用FStand和C++,我希望我的程序是打印出我的.txt文件的内容。这可能很简单,但我在网上看过很多东西,却找不到任何对我有帮助的东西。我该怎么做?以下是我目前掌握的代码: #include <iostream> #include <fstream> using namespace std; int main() { string output; ifstream myfile; ofstream myfile2; string STRING; myfile.open ("/Volumes/LFARLEIGH/Lucas.txt"); myfile2 << "Lucas, It Worked"; myfile >> STRING; cout << STRING << endl; myfile.close(); return 0; } #包括 #包括 使用名称空间std; int main(){ 字符串输出; ifstreammyfile; 流myfile2; 字符串字符串; myfile.open(“/Volumes/LFARLEIGH/Lucas.txt”); myfile2>字符串; 当这个功能已经在标准C++库中实现时,没有理由重新发明轮子。 #include <iostream> #include <fstream> int main() { std::ifstream f("file.txt"); if (f.is_open()) std::cout << f.rdbuf(); } #包括 #包括 int main() { std::ifstream f(“file.txt”); 如果(f.是开着的()) std::cout#包括 #包括 int main() { 字符串名; std::ifstream数据文件(“file.txt”); 而(!dataFile.fail()&&!dataFile.eof()) { 数据文件>>名称; cout,c++,iostream,fstream,C++,Iostream,Fstream,试试这个,只是在某些地方修改了。您曾尝试使用提取器(即ifstream)打开一个文件,但使用插入器(即ofstream)覆盖了这个文件 在没有打开文件的情况下,ifstream和ofstream是两个不同的类。因此,他们不理解 #include<iostream> #include<fstream> using namespace std; int main(){ string output; ifstream myfile; ofstrea

试试这个,只是在某些地方修改了。您曾尝试使用提取器(即ifstream)打开一个文件,但使用插入器(即ofstream)覆盖了这个文件 在没有打开文件的情况下,ifstreamofstream是两个不同的类。因此,他们不理解

#include<iostream>
#include<fstream>

using namespace std;

int main(){

    string output;
    ifstream myfile;
    ofstream myfile2;

    string STRING;
    // output stream || inserting
    myfile2.open ("/Volumes/LFARLEIGH/Lucas.txt");

    myfile2 << "Lucas, It Worked";


    myfile2.close();

    // input stream || extracting

    myfile.open("/Volumes/LFARLEIGH/Lucas.txt");

        myfile >> STRING;
        cout << STRING << endl;
    myfile.close();


   return 0;
}
#包括
#包括
使用名称空间std;
int main(){
字符串输出;
ifstreammyfile;
流myfile2;
字符串字符串;
//输出流| |插入
myfile2.open(“/Volumes/LFARLEIGH/Lucas.txt”);
myfile2>字符串;

你会有错误吗有一个额外的“}“在你能打开同一个文件两次之后?很抱歉这些事情-不相关。我没有收到错误,文件中的文本只是没有显示出来?你能解释一下你的代码吗?为什么它比?在回答时,请说明实际发布的代码中有什么错误,哪些错误被更正,以及为什么必须在该wa中更正。”y、 下面的链接将帮助您。
#include<iostream>
#include<fstream>

using namespace std;

int main(){

    string output;
    ifstream myfile;
    ofstream myfile2;

    string STRING;
    // output stream || inserting
    myfile2.open ("/Volumes/LFARLEIGH/Lucas.txt");

    myfile2 << "Lucas, It Worked";


    myfile2.close();

    // input stream || extracting

    myfile.open("/Volumes/LFARLEIGH/Lucas.txt");

        myfile >> STRING;
        cout << STRING << endl;
    myfile.close();


   return 0;
}