getline() 的原型/库是什么;
What's the prototype/library for getline();
我想使用getline((;函数。我把#include放在了标题处。但我得到了一个错误,说"函数‘getline’应该有一个原型"。图书馆错了吗?或者我需要另一个图书馆?这是我的代码
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<iostream.h>
void main(){
char word;
ofstream file;
file.open("code.txt");
file.close();
while(getline(file,word))
{
cout<<word<<"n";
}
getch();
}
您的问题是getline()
适用于getline(ifstream, string)
而不是getline(ofstream, char)
。因此,您的代码应该更像这样:
string word;
ifstream myFile("code.txt");
while(getline(myFile,word))
cout<< word<< "n";
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- C++避免重复声明的语法是什么
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- C++中名称篡改的目的是什么
- 在 c++ 中拥有一组结构的正确方法是什么?
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 是什么阻止DOMTimerCoordinator::NextID进入无休止的循环
- 派生类销毁的最佳实践是什么
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 通过JNI传递数据数组的最快方法是什么
- "using namespace std;"在C++的作用是什么?
- 在两台机器之间进行时间戳的最佳c++chrono函数是什么
- getline() 的原型/库是什么;
- 在C++中包含原型文件的正确方法是什么?
- 在函数中拥有函数原型的目的是什么?
- C++:在匿名命名空间中声明函数原型的正确方法是什么
- Boost::signals2::signal::connect 的原型是什么?