String to int/float

Well, I'm making a program that reads flom a external .txt file.
The problem here is, when I read the .txt, i use this...
1
2
3
4
5
6
7
8
  string linea;
  ifstream file("database.txt");
    if(file.is_open())
    {
        while(getline(file,linea))
        {
...
and more...


The lines are saved in my string "linea".
But i need to convert some of them to int (cause the .txt have 2 lines of string, and 3 lines of int/float, and again 2 lines of string, 3 lines of int... etc...

Somebody knows how to do that?
(btw, im not a english speaker, if its something you dont understand please ask :$)

Thanks!
Converting a string to an int:

int x = std::stoi(input_string);

This will throw an exception if the input_string isn't something that can be sensibly interpreted as an int.
http://en.cppreference.com/w/cpp/string/basic_string/stol

"Stoi" was not decladed in this scope, do I need a special header,
I have this

1
2
3
4
#include <iostream>
#include <string.h>
#include <cstring>
#include <cstdlib> 
closed account (E0p9LyTq)
For std::stoi you need the <string> C++ header and a C++11 compiler.

<string.h> and <cstring> are the same header, C strings in the C library.
Thanks, I just had to "activate" c++11
Thank You so Much :D
Topic archived. No new replies allowed.