Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C / C ++ various data types Conversion Summary     - CentOS 6.x systems installation + NIC driver installation (Realtek PCIe GBE Family Controller for Linux) (Linux)

- To explore the Android ListView caching mechanism again (Programming)

- Different versions of MongoDB achieve master-slave replication (Database)

- Object-C in the preparation of multi-parameter function parameter is omitted (Programming)

- Tsung first test installation (Linux)

- MySQL Tutorial: Philosophical Reflections on the unauthenticated user (Database)

- Use Visual Studio 2015 to develop Android program (Programming)

- To remove those IP is prohibited Fail2ban on CentOS 6/7 (Server)

- Use Pylint regulate your Python code (Programming)

- Varnish configuration language VCL and its built-in variables (Server)

- How to run Kali Linux 2.0 in Docker container (Linux)

- OpenvSwitch 2.1.2 shell script to start and stop (Linux)

- Using FTPClient to upload and download files in Java (Programming)

- To convert into a binary search tree sorted doubly linked list (Programming)

- Mounting kit under Fedora Linux (Linux)

- Learning OpenCV: (VS2010-openCV2.4.3-win7 configuration instructions) (Linux)

- Wi-Fi hackers use to attack your seven methods (Linux)

- Linux System Administrator Network Security Experience (Linux)

- A new method for Linux hidden files (Linux)

- Bug tracking library after FastJson omitted the decimal point 0 (Programming)

 
         
  C / C ++ various data types Conversion Summary
     
  Add Date : 2016-06-06      
         
       
         
  The following is a Windows / Linux systems commonly used in C / C ++ various data types Conversion Summary:

#include < stdio.h>
#include < stdlib.h>
#include < iostream>
#include < string>
#include < string.h>

int main ()
{
 // 1 -> int to char []
 int tmp1 = 100;
 char ch1 [15];
 sprintf (ch1, "% d", tmp1);
 std :: cout << ch1 << std :: endl;

 // 2 -> int to string
 int tmp2 = 111;
 char ch2 [15];
 sprintf (ch2, "% d", tmp2);
 std :: string str2;
 str2 = std :: string (ch2);
 std :: cout << str2 << std :: endl;

 // 3 -> int to enum
 enum enum3 {
  A,
  B
 };
 int tmp3 = 222;
 enum3 val3 = static_cast < enum3> (tmp3);
 std :: cout << val3 << std :: endl;

 // 4 -> char [] to string
 char arr4 [] = "this is a sample";
 std :: string str4;
 str4 = std :: string (arr4);
 std :: cout << str4 << std :: endl;

 // 5 -> char to int
 char ch5 = '8';
 int val5 = ch5 - '0'; // val5 is bounded by 0 to 9
 std :: cout << val5 << std :: endl;

 // 6 -> char [] to int
 char arr6 [] = "12345";
 int tmp6;
 sscanf (arr6, "% d", & tmp6);
 std :: cout << tmp6 << std :: endl;

 // 7 -> char * to int
 char * pch7 = "444";
 int tmp7;
 tmp7 = atoi (pch7);
 std :: cout << tmp7 << std :: endl;

 // 8 -> char * to float
 char * pch8 = "55.5";
 float tmp8;
 tmp8 = (float) atof (pch8);
 std :: cout << tmp8 << std :: endl;

 // 9 -> char * to double
 char * pch9 = "66.666";
 double tmp9;
 tmp9 = atof (pch9);
 std :: cout << tmp9 << std :: endl;

 // 10 -> float to char []
 float tmp10 = 11.11;
 char ch10 [20];
 sprintf (ch10, "% f", tmp10);
 std :: cout << ch10 << std :: endl;

 // 11-> int to char *
 int tmp11 = 777;
 char * pch11;
 char ch11 [20];
 sprintf (ch11, "% d", tmp11);
 pch11 = ch11;
 std :: cout << pch11 << std :: endl;

 // 12 -> double to char []
 double tmp12 = 8.888;
 char arr12 [20];
 sprintf (arr12, "% f", tmp12);
 std :: cout << arr12 << std :: endl;

 // 13 -> char * to string
 char * pch13 = "hello, world";
 std :: string str13;
 str13 = std :: string (pch13);
 std :: cout << str13 << std :: endl;

 // 14 -> string to char []
 std :: string str14 = "dog, cat";
 char arr14 [255];
 strncpy (arr14, str14.c_str (), sizeof (arr14));
 arr14 [sizeof (arr14) - 1] = 0;
 std :: cout << arr14 << std :: endl;

 // 15 -> string to const char *
 std :: string str15 = "ha ha";
 const char * pch15;
 pch15 = str15.c_str ();
 std :: cout << pch15 << std :: endl;

 // 16 -> float to int
 float ftmp16 = 99.99;
 int tmp16;
 tmp16 = static_cast < int> (ftmp16); // static_cast < int> (ftmp16 + 0.5)
 std :: cout << tmp16 << std :: endl;
 
 return 0;
}
     
         
       
         
  More:      
 
- Category prevent DoS attacks against Linux (Linux)
- How to compile and install wxWidgets in Ubuntu / Debian / Linux Mint (Linux)
- CentOS How to mount the hard drive (Linux)
- Linux System Getting Started Learning: Debian download, installation and graphical interface (Linux)
- Linux host dual LAN transceiver package ARP problem (Linux)
- 12 Linux Process Management Commands (Linux)
- Android first line of code study notes (Programming)
- TWiki LDAP error appears the problem is solved (Linux)
- Wireshark basic introduction and learning TCP three-way handshake (Linux)
- LogStash log analysis display system (Linux)
- Deepin Tutorial: Depth Description Installer expert mode (Linux)
- IDS Intrusion Detection System built (Linux) (Linux)
- LAN Deployment Docker-- from scratch to create your own private warehouse Docker (Linux)
- CentOS5 installation Nodejs (Linux)
- Recover accidentally deleted Nginx logs (Server)
- CentOS Linux Optimization and real production environment (Linux)
- CentOS7 method to upgrade the kernel to 3.18 (Linux)
- How to install PlayOnLinux 4.2.5 under Ubuntu 14.04 / 12.04 (Linux)
- cat command uses the Linux redirection merge files (Linux)
- Visual Studio Code experience (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.