首页 > 解决方案 > 如何在 Ubuntu 中将内容从一个文件传输到另一个文件。?

问题描述

我正在尝试将一个文件的内容复制到 linux 中的另一个文件。我认为我的逻辑是正确的,但我不明白错误是什么。

我的函数有 3 个参数。第三个参数是一个字符串,它是应该从中读取内容的文件名。

#include<iostream>
#include <curses.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
void process(int cvar, int cclause, string fnm)
{
    ifstream fs;
    ofstream ft;

    fs.open("contents.txt");
    if(!fs)
    {
        cout<<"Error in opening source file..!!";
    }
    ft.open(fnm,ios::app);
    if(!ft)
    {
        cout<<"Error in opening target file..!!";
        fs.close();
    }

char str[255];
while(fs.getline(str,255))
{
    ft<<str;
}



    cout<<"File copied successfully..!!";
    fs.close();
    ft.close();
    getch();
}

这是我得到的错误:

g++ mainProj.cpp -lz3
/tmp/ccLBpiRs.o: In function `process(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
mainProj.cpp:(.text+0x172): undefined reference to `stdscr'
mainProj.cpp:(.text+0x17a): undefined reference to `wgetch'
collect2: error: ld returned 1 exit status

标签: c++file

解决方案


#include <ncurses.h>并与 -lncurses 链接。

更多在这里


推荐阅读