C++ 如何将整个文本文件复制到c++; intmain() { char ch; 字符文本[500]; chars[500]; ifstream-fin(“bitch.txt”,ios::in); 而(!fin.eof()) { 财政司司长(s,500); } fin.close(); 对于(inti=0;i

C++ 如何将整个文本文件复制到c++; intmain() { char ch; 字符文本[500]; chars[500]; ifstream-fin(“bitch.txt”,ios::in); 而(!fin.eof()) { 财政司司长(s,500); } fin.close(); 对于(inti=0;i,c++,arrays,string,file,borland-c++,C++,Arrays,String,File,Borland C++,只需这样做 int main() { char ch; char text[500]; char s[500]; ifstream fin("bitch.txt",ios::in); while(!fin.eof()) { fin.getline(s,500); } fin.close(); for (int i=0; i<500; i++) { cout << s[i]; } return 0; } 是您要查找的数组。如果要将文件的完整内容复制到char数组中,则

只需这样做

int main()
{
char ch;
char text[500];
char s[500];

ifstream fin("bitch.txt",ios::in);
while(!fin.eof())
{
fin.getline(s,500);
}
fin.close();

for (int i=0; i<500; i++)
{
   cout << s[i];
}
return 0;
}

是您要查找的数组。

如果要将文件的完整内容复制到char数组中,则无需逐行执行。您只需复制文件的完整内容即可

您可以使用以下命令将整个文件读入字符串:

str.c_str();
std::ifstream-in(“FileReadExample.cpp”);
std::字符串内容((std::istreambuf_迭代器(in)),
std::istreambuf_迭代器();
然后可以使用contents.c_str()获取字符数组

看下面的链接,他给出了正确的答案

没有任何更简单的代码,BTW我使用Borland C++ SoO,IDK,如果这将不会有任何更简单的,对于原始编译程序显示你希望在柜橱里得到一个算盘,如果你想用这个为什么?下载GNU一个开始
str.c_str();
std::ifstream in("FileReadExample.cpp");
std::string contents((std::istreambuf_iterator<char>(in)), 
std::istreambuf_iterator<char>());