※ [本文转录自 ric2k1 信箱]
标题: 想请问关於ifstream open file的问题...
时间: Mon Dec 21 23:56:52 2009
在作业六里面,readCir传入的参数是string&
但是ifstream 的open function的传入参数是char*
我稍微试了一下,发现 char* c = "blahblah"; string s = c; 这样写是可以的
但是相反过来就不行?? string s ="blahblah"; char* c = s; (compile error!!)
所以我在测试的时候readCir都传char*进去...
可是又发生其他问题,当我写 char* fileName = "C17.cir"; 传进readCir没有问题
但当我写 char* fileName; cin >> fileName; 再传进去就有问题了
程式会在测试用的main里面所有东西执行完之後最後发生"记忆体区段错误"的讯息
ddd的错误讯息是segmentation fault,然後是停在 #include<string.h>前面...
不明白...这到底是为什麽呢??
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.224.46.80
※ 编辑: ric2k1 来自: 61.224.46.80 (12/22 02:00)
1F:推 kiokio:string s ="blahblah"; const char* c = s.c_str(); 12/22 14:20