简体   繁体   中英

SystemC sc_uint from String Object

I've started using SystemC recently and wanted to write a simple program that reads numbers from a file in the SystemC string format and converts them into sc_uint types. Somehow the simple program always fails during the conversion

The program:

#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 );
}

The ex3_2.dat file

0x1234\n

The output

Error: (E403) conversion failed: character string is empty

I do not get why the conversion breaks.

c_str() should return a const char*.

Printing the String to cout shows the right value for line.

Static assignments like "0x1234" do work. Does somebody have an idea?

The following code

#include <systemc.h>
#include <fstream>
#include <string>

#include <iostream>

int sc_main( int argc, char *argv[] ){

    std::ifstream in_file;
    std::string line;

    in_file.open( "ex3_2.dat", ios::in );

    while( getline( in_file, line ) ){
        sc_uint<29> x = line.c_str();
       std::cout << "0x" << std::hex << x << '\n';
    }

    return 0;
}

with the ex3_2.dat file

0x1234
5
6
7
8

compiled with the following

g++ -std=c++11 -Wall -o main.o main.cpp -lsystemc

produces

0x00001234
0x00000005
0x00000006
0x00000007
0x00000008

g++ --version = g++ (GCC) 7.1.0

No compiler warnings or errors are emitted. The conclusion being that the code itself is fine. Perhaps look for the errors elsewhere, what std library versions are linked etc. Hidden characters in the file? ASCII vs UTF-8? Too many possibilities to narrow it down from here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM