Im working on a new Project but i need your help converting a std::string to double!

I dont know why i get the LNK error so i hope someone of you know it :).

Here are the includes...

#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <string>

ok i think that only stdlib.h and stdio.h is necessary for that function but ok here is the function.

double toDouble(string in){

double out = atof(in.data());

return out;

it should work right? but it doesnt :(.

Here is the error... in german :x

Fehler 1 error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl calcstring(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?calcstring@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z)" in Funktion ""void __cdecl calc3(void)" (?calc3@@YAXXZ)". TaschenRechner.obj

I think i have to include a lib with #pragma comment(lib, "xXx");
but i dont know which :o... MSDN wont help me :'(.


Recommended Answers

All 4 Replies

I think you mean: double out = atof(in.[B]c_str()[/B]) instead of double out = atof(in.data())

Thanks, but it doesent work too :(

> Here is the error... in german :x
Except that seems to suggest the problem is in a function called calc3() and not one called toDouble().

Did you fix it in all the places?

Posting new error messages would be better than "it didn't work".

Oh no im such a fool... No error is in this function but in another one :o. Sorry guys :x

Thanks Salem :) Fixed it now ;)...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.