getline() error
getline() error
我正在编写这个函数,它将一个文件的内容复制到另一个文件中。我在while循环中使用getline()函数。不知何故,编译器给了我一个错误。你知道为什么吗?下面是我的代码:
#include<iostream>
#include<cstdlib>
#include <fstream>
using namespace std;
// Associate stream objects with external file names
#define inFile "InData.txt" // directory name for file we copy from
#define outFile "OutData.txt" // directory name for file we copy to
int main(){
int lineCount;
string line;
ifstream ins; // initialize input object an object
ofstream outs; // initialize output object
// open input and output file else, exit with error
ins.open("inFile.txt");
if(ins.fail()){
cerr << "*** ERROR: Cannot open file " << inFile
<< " for input."<<endl;
return EXIT_FAILURE; // failure return
}
outs.open("outFile.txt");
if(outs.fail()){
cerr << "*** ERROR: Cannot open file " << outFile
<< " for input."<<endl;
return EXIT_FAILURE; // failure return
}
// copy everything fron inData to outData
lineCount=0;
getline(ins,line);
while(line.length() !=0){
lineCount++;
outs<<line<<endl;
getline(ins,line);
}
// display th emessages on the screen
cout<<"Input file copied to output file."<<endl;
cout<<lineCount<<"lines copied."<<endl;
ins.close();
outs.close();
cin.get();
return 0;
}
谢谢你的帮助。
编辑:对不起,这里是错误:1. "错误C3861: 'getline':标识符未找到"2. "错误C2679:二进制'<<':找不到接受右操作数'std::string'类型的操作符(或者没有可接受的转换)"
一个问题是您没有包含<string>
头文件,这是定义getline的地方。
相关文章:
- "error: no matching function for call to"构造函数错误
- Seg Fault Issue C++ (file IO / getline)
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 当用户键入分隔符时,停止getline()输入
- C++错误:"error: int aaa::bbb is protected within this context"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- getline() 的原型/库是什么;
- 错误 没有与参数列表匹配的重载函数"getline"实例
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 如何在 c++ 中使用 ',' 作为 getline 分隔符
- 错误:调用'getline'没有匹配函数
- 如何在 c++ 中使用 getline 从文件中读取字符串?
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- Error with getline
- C++ getline error
- getline() error
- Error with getline ifstream
- Error with std::getline