Cara konversi string ke integer/float di C++

DEV C++

#include <iostream>

#include<sstream>

using namespace std;

int main()

{

string nml={“1000.111″};

float harga=0;

stringstream(nml) >>harga; // konversi string ke float, integer

cout << “Jadi harga total: “ << 10*harga << endl;

return 0;

}

Sintaks stringstream ini berguna untuk mengkonversi string ke integer/float. Tapi harus ada #include <sstream>

Explore posts in the same categories: Kuliah

Tinggalkan Balasan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Ubah )

Twitter picture

You are commenting using your Twitter account. Log Out / Ubah )

Facebook photo

You are commenting using your Facebook account. Log Out / Ubah )

Connecting to %s


Ikuti

Get every new post delivered to your Inbox.