Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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++ 在(while(info[x]!=';';)时发生访问冲突错误 #包括 #包括 #包括 使用名称空间std; void main() { 字符信息[81]; 字符串名[5]; 双倍销售[5][5]; 整数计数=0; int x=0; ifstream文件; 打开(“sales.txt”); 而(!file.eof()) { x=0; getline(info,80); 而(信息[x]!=(字符)39) { while(信息[x]!='') { 名称[计数]+=信息[x]; x++; } x++; 对于(int y=0;y_C++_Loops_Cstring - Fatal编程技术网

C++ 在(while(info[x]!=';';)时发生访问冲突错误 #包括 #包括 #包括 使用名称空间std; void main() { 字符信息[81]; 字符串名[5]; 双倍销售[5][5]; 整数计数=0; int x=0; ifstream文件; 打开(“sales.txt”); 而(!file.eof()) { x=0; getline(info,80); 而(信息[x]!=(字符)39) { while(信息[x]!='') { 名称[计数]+=信息[x]; x++; } x++; 对于(int y=0;y

C++ 在(while(info[x]!=';';)时发生访问冲突错误 #包括 #包括 #包括 使用名称空间std; void main() { 字符信息[81]; 字符串名[5]; 双倍销售[5][5]; 整数计数=0; int x=0; ifstream文件; 打开(“sales.txt”); 而(!file.eof()) { x=0; getline(info,80); 而(信息[x]!=(字符)39) { while(信息[x]!='') { 名称[计数]+=信息[x]; x++; } x++; 对于(int y=0;y,c++,loops,cstring,C++,Loops,Cstring,当我运行这个程序时,我会遇到一个运行时错误,但我不能确切地找出原因。我不太熟悉我的编译器调试器,因此调试时遇到问题。我认为“x”超出了数组(info)的界限。在再次进入循环之前,应检查x是否小于81 例: 而且,这一行很容易出错。我建议你把它分成更小的部分,更容易理解(并且不太依赖于线的确切长度)。您甚至可以使用格式化输入来获取数字 stringStream >> names[count]; string theNextString;

当我运行这个程序时,我会遇到一个运行时错误,但我不能确切地找出原因。我不太熟悉我的编译器调试器,因此调试时遇到问题。

我认为“x”超出了数组(info)的界限。在再次进入循环之前,应检查x是否小于81

例:

而且,这一行很容易出错。我建议你把它分成更小的部分,更容易理解(并且不太依赖于线的确切长度)。您甚至可以使用格式化输入来获取数字

        stringStream >> names[count];
        string theNextString;
        stringStream >> theNextString;
        // Process the theNextString, which is the string after the last space (and until the next one)
使用格式化输入,它看起来像

sales[count][atoi(&info[x])] = (atoi(&info[x + 1]) * 10) + atoi(&info[x+2]) + (.01 *((atoi(&info[x+4])*10) + atoi(&info[x+5])));

请注意,只有当您的数字以空格分隔时,上述方法才有效。

我认为“x”超出了数组(info)的界限。在再次进入循环之前,应检查x是否小于81

例:

而且,这一行很容易出错。我建议你把它分成更小的部分,更容易理解(并且不太依赖于线的确切长度)。您甚至可以使用格式化输入来获取数字

        stringStream >> names[count];
        string theNextString;
        stringStream >> theNextString;
        // Process the theNextString, which is the string after the last space (and until the next one)
使用格式化输入,它看起来像

sales[count][atoi(&info[x])] = (atoi(&info[x + 1]) * 10) + atoi(&info[x+2]) + (.01 *((atoi(&info[x+4])*10) + atoi(&info[x+5])));

请注意,只有当您的数字以空格分隔时,上述内容才有效。

再次检查后,我推测可能是您的这行代码:

int firstNumber;
stringStream >> firstNumber;

你肯定超出了
info
的范围,进入了另一个内存位置。这很可能是导致内存访问冲突的原因。

再次检查后,我推测可能是您的这行代码:

int firstNumber;
stringStream >> firstNumber;

你肯定超出了
info
的范围,进入了另一个内存位置。这很可能是导致内存访问冲突的原因。

多么可怕的代码。为什么不能使用
std::string
std::getline
?没有人会认真地去调试那些乱七八糟的东西。如果你说
(char)39
,那么你也应该说
x=(int)0
,不是吗?代码太可怕了。为什么不能使用
std::string
std::getline
?没有人会认真地去调试那些乱七八糟的东西。如果你说
(char)39
,那么你也应该说
x=(int)0
,不是吗?