Put a Number from a .txt file to a int variable ?
I have a .txt file(file1) that contains one number: 1
What I want to do now is in my code below put this Number that in this case is: 1 into the variable: "int tal = 0"
How is it possible to do this ? I suppose the number 1 is considered to be a string in the textfile ?
Thanks.
Code:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main ()
{ char Number[20];
int tal = 0;
ofstream Test;
Test.open ("file2.txt");
ifstream myfile ("file1.txt");
myfile >> Number;
Test << tal <<"\n";
return 0;
}