【发布时间】:2018-05-22 22:25:04
【问题描述】:
我最近开始使用SystemC,想编写一个简单的程序,从SystemC 字符串格式的文件中读取数字并将它们转换为sc_uint 类型。不知何故,这个简单的程序在转换过程中总是失败
程序:
#include <systemc.h>
#include <fstream>
#include <string>
int sc_main( int argc, char *argv[] ){
ifstream in_file;
std::string line;
char *buffer;
in_file.open( "ex3_2.dat", ios::in );
while( getline( in_file, line ) ){
sc_uint<29> x = line.c_str();
}
return( 0 );
}
ex3_2.dat 文件
0x1234\n
输出
错误:(E403)转换失败:字符串为空
我不明白为什么转换会中断。
c_str() 应该返回一个 const char*。
将字符串打印到 cout 会显示 line 的正确值。
像“0x1234”这样的静态分配确实有效。 有人有想法吗?
【问题讨论】:
-
你试过打印字符串吗?是你预期的吗?
-
是的。打印字符串完全符合我的预期“0x1234”
-
这个错误还有其他上下文吗?这是运行时异常而不是编译错误,对吧?
-
没有编译工作没有问题。执行从正常的 SystemC 标头开始,然后是错误。