xxxxxxxxxx
using System;
namespace Dates
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter date");
string dateInput = Console.ReadLine();
Console.WriteLine("Enter time");
string timeInput = Console.ReadLine();
Console.WriteLine("Enter number of hours to add");
string hoursInput = Console.ReadLine();
int hours = int.Parse(hoursInput);
string[] timeParts = timeInput.Split(":");
string[] dateParts = dateInput.Split("-");
DateTime date = new DateTime(
int.Parse(dateParts[0]),
int.Parse(dateParts[1]),
int.Parse(dateParts[2]),
int.Parse(timeParts[0]),
int.Parse(timeParts[1]),
0
);
date = date.AddHours(hours);
Console.WriteLine(date.ToString("yyyy-MM-dd HH:mm"));
}
}
}
xxxxxxxxxx
// "std::string" has a method called "c_str()" that returns a "const char*"
// pointer to its inner memory. You can copy that "const char*" to a variable
// using "strcpy()".
std::string str = "Hello World";
char buffer[50];
strcpy(buffer, str.c_str());
std::cout << buffer; //Output: Hello World
//POSTED BY eferion ON STACK OVERFLOW (IN SPANISH).
xxxxxxxxxx
// example
char sczName[] = {"Jakes"};
std::string strName = std::string(sczName);
/* SYNTAX
#include <string>
std::string(<char-to-convert>)
*/