# Thread: How do i use the split() to seperate numbers

1. ## How do i use the split() to seperate numbers

#include <iostream.h>
#include <conio.h>
int main()
{
double Number, Decimal;
int Integer;
cout << "Enter decimal number: ";
cin >> Number; cin.ignore();

cout << "\nIntegerl: " << Integer << " and decimal: " << Decimal;
cout << "\n\npress a button"; getch();
return 0;
}

So if i enter 19.84444

I want it to say Integer 19 and decimal 0.84444

I have no idea how to use the split() function

2. Which "split" function are we talking of here? As far as I'm aware, there is no standard function called "split".

--
Mats

3. split isn't a standard function. Search your C++ reference for modf, that does what you want.

4. Originally Posted by Prelude
split isn't a standard function. Search your C++ reference for modf, that does what you want.
Cheers

I found modf

double modf(double x, double *y);

That's all that's written about it, could you please show me how to use it ?

5. First hit on google, and it has an example: http://www.cplusplus.com/reference/c...math/modf.html

6. Fantastic, i just googled the split() and came up with nothing

Cheers

7. Another option (just for the sake of expressing alternate methods)

Example:
Code:
```#include <sstream>
#include <iostream>

int main(void)
{
std::stringstream s;
float x;

std::cout << "Please input a number: ";
std::cin >> x;

s << x;

std::string whole, decimal;
size_t pos = s.str().find(".");

whole = s.str().substr(0,pos);
decimal = std::string("0") + s.str().substr(pos);

std::cout << whole << " and " << decimal << std::endl;

return 0;
}```

Popular pages Recent additions