Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
¿Existe una forma portátil en C ++ estándar para recuperar el nombre de host?

Estoy trabajando en un programa C++ que necesita usar el nombre de host de la computadora en la que se está ejecutando. Mi método actual para recuperar esto es manipular una API C como esta:

 char *host = new char[1024]; gethostname(host,1024); auto hostname = std::string(host); delete host;

¿Existe un método portátil moderno de C++ para hacer esto, sin incluir una gran biblioteca externa (por ejemplo, boost)?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

No, no hay soporte estándar de C++ para esto. Tendrá que crear su propia función u obtener una biblioteca que tenga esta funcionalidad.

over 4 years ago · Santiago Trujillo Report

0

#include <string> //#include <winsock.h> //Windows //#include <unistd.h> //Linux std::string GetHostName(void) { std::string res = "unknown"; char tmp[0x100]; if( gethostname(tmp, sizeof(tmp)) == 0 ) { res = tmp; } return res; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!