I'm having some trouble with the code from the Convert a string to a int (C++)
I've only changed it a little bit. Here's what I got so far:
I get the following error:Code:#include <sstream> #include <string> #include <iostream> //I added this using namespace std; bool StringToInt(const string &s, int &i); int main() { string s1 = "12"; string s2 = "ZZZ"; int result; if (StringToInt(s1, result)) { cout << "The string value is " << s1 << " and the int value is " << result << endl; } else { cout << "Number conversion failed" <<endl; } if (StringToInt(s2, result)) { cout << "The string value is " << s2 << " and the int value is " << result << endl; } else { cout << "Number conversion failed on " <<s2 <<endl; } return 0; } bool StringToInt(const string &s, int &i) { istringstream myStream(s); if (myStream>>i) return true; else return false; } /* * Program output: The string value is 12 and the int value is 12 Number conversion failed on ZZZ * */
--------------------Configuration: onlyatest - Win32 Debug--------------------
Compiling...
thisisatest.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/onlyatest.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
onlyatest.exe - 2 error(s), 0 warning(s)
I think the error comes from the fact that "result" is never assigned a value. Can anyone give me a hand on who to fix this? I am using Visual C++ 6.0.
Thanks



LinkBack URL
About LinkBacks


