访问冲突读取位置0xCCCCCCCC
Access violation reading location 0xCCCCCCCC
我正在编写一个程序,读取一个有一堆销售数字的文本文件,它工作得很好,除了我不断得到一个错误,其中指出:访问违反读取位置0xCCCCCCCC。
下面是我代码的相关部分:如有任何帮助,我将不胜感激。
void task1()
{
// const int MAX_CHARS_PER_LINE = 512;
// const int MAX_TOKENS_PER_LINE = 20;
//const char* const DELIMITER = " ";
string year;
string line;
double unitsold1[12],unitsold2[12],unitprice1[12],unitprice2[12];
string month[12];
string name="D:\Sandesh Pyakurel\Model_X_Sale_";
cout<<"nPlease enter a year in the yyyy format: ";
cin>>year;
string result=name+year+".txt";
ifstream myfile;
myfile.open(result.c_str());
double a,b,c,d;
if(!myfile)
{
cout<<"Could not open file"<<endl;
}
if (myfile.is_open())
{
int count =0;
while (myfile>>month[count]
>>unitsold1[count]
>>unitprice1[count]
>>unitsold2[count]
>>unitprice2[count] )
{
count++;
}
myfile.close();
for(int i=0;i<=count;i++)
{
cout<<month[i]<<" "<<unitsold1[i]<<" "<<unitprice1[i]<<" " <<
unitsold2[i]<<" "<<unitprice2[i]<<" "<<endl;
}
/*
char myarray[5];
for(int i=0;i<=5;i++)
{ myfile.getline(myarray,100);
cout<<myarray[i];
}
*/
/*
char buf[100];
myfile.getline(buf,100);
int n=0;
const char* token[100]={};
token[0]=strtok(buf,DELIMITER);
if(token[0])
{
for (n=1;n<MAX_TOKENS_PER_LINE;n++)
{
token[n]=strtok(0,DELIMITER);
if(!token[n])
break;
}
}
for(int i=0;i<n;i++)
{
stringstream ss(token[i]);
ss>>tmp>>a>>b>>c>>d;
cout<<ss<<endl;
}*/
}
}
假设您的输入文件中有12个月,您正在读取数组末尾以外的内容。替换:
for(int i=0;i<=count;i++)
{
:
for( int i=0; i < count; ++i )
{
相关文章:
- 将值指定给向量(2D)的向量中的某个位置
- 使用Unreal C++获取VR耳机的世界位置/方向
- 写入位置0x0000000C时发生访问冲突
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 如何使用cudaMallocManaged在指针位置初始化对象?(C++)
- 无法获取webot::PositionSensor对象中位置传感器的值
- 非常量变量只读位置的赋值
- 创建 2D 数组0xCCCCCCCC访问冲突写入位置
- 0xC0000005:访问违规写入位置0xcccccccc
- 访问冲突读取位置0xcccccccc
- 访问违规读取位置 0xCCCCCCCC.using bool & unsigned short
- C++:xxx中0x00101890处未处理的异常:0xC0000005:读取位置0xcccccccc的访问冲突
- 写入位置0xCCCCCCCC的访问冲突
- 访问冲突读取位置0xCCCCCCCC
- 链接表中读取位置0xCCCCCCCC错误
- 访问冲突读取位置0xcccccccc
- 访问冲突读取位置0xCCCCCCCC
- 访问冲突写入位置0xcccccccc
- c++访问冲突写入位置0xCCCCCCCC