Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从c++;_C++_Input_Filestream - Fatal编程技术网

C++ 从c++;

C++ 从c++;,c++,input,filestream,C++,Input,Filestream,我试图获取一个输入文件,并将其逐字读取到数组中。主要的想法是,我试图计算字母表中每个字母出现的次数,记住a和a是不同的字母。我不认为这可能是最好的方法,但这正是我的大脑试图解决问题的方式 我的尝试: #include "hw05.h" int main() { const int MAX = 10000; //trying to figure out how to dynamically //allocate this to cooperate

我试图获取一个输入文件,并将其逐字读取到数组中。主要的想法是,我试图计算字母表中每个字母出现的次数,记住a和a是不同的字母。我不认为这可能是最好的方法,但这正是我的大脑试图解决问题的方式

我的尝试:

#include "hw05.h"
int main() {
const int MAX =  10000; //trying to figure out how to dynamically
                        //allocate this to cooperate with any file
ifstream inFile;
string file;
char fileAr[MAX];
int index;
index = 0;
size = 0;

inFile.open("hw05data.txt");
while (inFile) {
    inFile.get(fileAr[index]);
    index++;
}
cout << fileAr[10] << endl; //this is just to check if its working
inFile.close();
return 0; 
}
#包括“hw05.h”
int main(){
const int MAX=10000;//正在尝试了解如何动态
//分配此文件以配合任何文件
河流充填;
字符串文件;
字符文件[MAX];
整数指数;
指数=0;
尺寸=0;
infle.open(“hw05data.txt”);
while(填充){
获取(文件[索引]);
索引++;
}

无法尝试使用地图容器。它负责分配和统计字母出现次数。

该代码是否有效?256个元素数组的可能重复将允许您统计所有可能的字符(反圣骑士除外,因为他们对字符代码撒谎。混乱邪恶你知道)在标准8位字符集中。因此,读取一个字符,将其用作数组索引,增加该索引,然后只打印您关心的索引。