关于C++用sprintf步骤字符串转字符数组

关于C++用sprintf方法字符串转字符数组
代码如下:
#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "opencv2/opencv.hpp"
#include "windows.h"

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
String path="E:/编程/c#/opencv/opencvtest/Debug/image";
Directory  dir;
vector<String> fileNames = dir.GetListFiles(path, "*.jpg", false); 
vector<String> fileFullName(fileNames.size());
for(int i=0; i < fileNames.size(); i++)  
{  
    String fileName = fileNames[i];  
    fileFullName[i] = path + fileName; 
}  

for(vector<string>::size_type i = 0; i < fileFullName.size(); ++i)
{   
char* a = new char(fileFullName[i].length()+1);
sprintf(a ,"%s" , fileFullName[i].c_str());
cout<<a<<endl;
}
system("pause");
}

我这个程序是想遍历image目录下的所有图片,返回图片地址与文件名到fileFullName数组。 然后将字符串数组的每一项转化成一个字符数组(cvLoadImage需要图片地址为字符数组)。 但是 运行的时候报错

显示cvtt.exe 已触发了一个断点。
------解决思路----------------------
char* a = new char(fileFullName[i].length()+1);

what the hell is this.........

char * a = new char(99);
char * a = new char[99];

they are NOT the same thing.....
------解决思路----------------------
引用:
Quote: 引用:

没细看代码,确定是sprintf的问题?调试一下吧;


额,刚刚找到问题了。 
char* a = new char(fileFullName[i].length()+1);
 是这个的问题
要将小括号改成中括号。 
char* a = new char[fileFullName[i].length()+1];
 
请问下这两个有什么区别?


new char();new 一个char并使用()中的值初始化
new char[];new 一个长度为[]中的字符数组