Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,914 questions

51,847 answers

573 users

How to concatenate two floats into a string in C++

1 Answer

0 votes
#include <iostream>
#include <iomanip> 
#include <sstream> 

int main() {
    float f1, f2;

    f1 = 31.748832;
    f2 = -893.98351;

    std::stringstream stream;
    stream << std::fixed << std::setprecision(4) << f1 << " " << f2;
    std::string s = stream.str();
    
    std::cout << s;
    
    return 0;
}



/*
run:

31.7488 -893.9835

*/

 



answered May 3, 2021 by avibootz

Related questions

1 answer 142 views
1 answer 211 views
1 answer 172 views
1 answer 152 views
1 answer 128 views
4 answers 302 views
302 views asked May 10, 2021 by avibootz
1 answer 166 views
166 views asked Jan 5, 2021 by avibootz
...