int StringToInteger(string num);
int StringToInteger(string num){
int value{0};
size_t i;
for(i = 0; i < num.size() ; ++i) {
value = value * 10 + (num[i] -'0');
}
return value;
}
#include <iostream>
using namespace std;
// the function prototype
int main() {
string num{"489"};
cout << StringToInteger(num) << endl;
return 0;
}
// implementation of StringToInteger
using namespace std
#pragma once to the top.
#pragma once #include <string> int StringToInteger(std::string num);
#include <iostream>
#include "converters.h"
using namespace std;
int StringToInteger(string num){
int value{0};
size_t i;
for(i = 0; i < num.size() ; ++i) {
value = value * 10 + (num[i] -'0');
}
return value;
}
g++ -o converters.o -c converters.cpp
#include "converters.h" at the top.
#include <iostream>
#include "converters.h"
using namespace std;
int main() {
cout << StringToInteger("345") << endl;
return 0;
}
OBJS = decConvert converTester
converters.o: converters.h
converTester: converters.o
g++ -e converters.cpp will show the output of the preprocessor
try g++ -v -o file file.cpp