查看简化的代码 - 我很困惑......
#include <stdio.h>
#include <string>
#include <cstdlib> // includes the standard library and overarchs over stdlib.h
using namespace std;
void main()
{
char buffer[10];
string theString;
int i = 997799; //(simplified)
itoa(i,buffer,10);
theString = buffer;
printf("\n string is: %s of length %d \n", theString, theString.length());
printf("\n buffer is: %s of length %d \n", buffer, theString.length());
return;
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是出乎意料的:
string is: (null) of length 926366009
buffer is: 997799 of length 6
Run Code Online (Sandbox Code Playgroud)
(1)为什么字符串打印为null?
(2) 为什么 theString.length() 在第一个 printf() 中打印不正确,但在第二个 printf() …
当我调用我的calculatePlaneEQ函数时,当我分配值时,它会抛出一个访问冲突...我的指针生锈了,但似乎这应该有效!
float *planeCoefA, *planeCoefB, *planeCoefC, *planeCoefD = NULL;
Run Code Online (Sandbox Code Playgroud)
呼叫:
calculatePlaneEQ (<...>, &planeCoefA, &planeCoefB, &planeCoefC, &planeCoefD);
Run Code Online (Sandbox Code Playgroud)
DEF:
void calculatePlaneEQ (<...>, float ** myXnorm, float ** myYnorm, float ** myZnorm, float** myD)
{
float xNorm = 1.3;
float yNorm = 1.4;
float zNorm = 1.5;
float eqD = 1.6;
*(*myXnorm) = xNorm;
*(*myYnorm) = yNorm;
*(*myZnorm) = zNorm;
*(*myD) = eqD;
}
Run Code Online (Sandbox Code Playgroud)