c++ - 如何在 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
解决方案
#include <ncurses.h>
并与 -lncurses 链接。
更多在这里。
推荐阅读
- python - 选择一个有效的选项。6da87c51321849bdb7da80990fdab19b 不是可用的选择之一
- python - python中的回调函数
- android-studio - 带有两个不同拇指的 Android Range Seekbar
- curl - 将 curl url 数据编码与不带查询字符串的 url 一起使用
- vue.js - 在vue3中更改axios名称,子组件说它没有定义
- python - 在odoo-12中显示组中的数字总和
- java - 删除 launch4j 中的 java 选项
- kotlin - Kotlin jvm html DOCTYPE
- arrays - 如何在 Kotlin 中创建可以保存任何数据类型(包括空值)的空数组
- vue.js - DaisyUI:当语言切换到 RTL 之一时,如何将方向切换到 RTL?