Skip to content

Instantly share code, notes, and snippets.

@piotoor
Created January 30, 2019 14:13
Show Gist options
  • Save piotoor/92f0bdfa52d85243ff725ac044869709 to your computer and use it in GitHub Desktop.
Save piotoor/92f0bdfa52d85243ff725ac044869709 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
#include <cstdlib>
#include <cstring>
using namespace std;
struct cmplx
{
double i, j;
cmplx(string str)
{
char * pch;
str.pop_back();
pch = strtok (const_cast<char*>(str.c_str())," +");
i = atof(pch);
pch = strtok (NULL, " +");
j = atof(pch);
}
friend ostream& operator<< (ostream& out, const cmplx& c)
{
out << c.i << " + " << c.j << "j";
return out;
}
};
cmplx operator "" _c(const char * str, size_t len)
{
cmplx ret(str);
return ret;
}
int main()
{
printf("Hello World\n");
cmplx com = "12 + 14j"_c;
cout << com << endl;
cmplx com2 = "12.5 + 21.4j"_c;
cout << com2 << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment