Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual C++ strings 1

Status
Not open for further replies.

sophtwarez

Programmer
Jan 8, 2002
8
0
0
US
So - does Microsoft support normal strings ala <string.h>?
As I go through the documentation it seems they have a special Win32 class called CString if you include <afx.h> but after including it I get serious linker problems when trying to execute.
Sample code:
#include <iostream.h>
#include <afx.h>
int main(){
CString t(&quot;this is a string&quot;);
return(0);
}
Error as follows:
Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/point.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

Got me stumped. I can use all the C standard stuff when I use the Borland Turbo Compiler, it just craps on me when I use Microsloth stuff.
 
Here is an example of what I'm trying to do:
#include <string>
#include <iostream.h>

using namespace std;

string pres[5];

void loadPrescriptions(){
//this will read from a file later
pres[0] = &quot;David Seruyange&quot;;
pres[1] = &quot;Laura Bush&quot;;
pres[2] = &quot;Jamie Myers&quot;;
pres[3] = &quot;Pamela Anderson Lee&quot;;
pres[4] = &quot;Grace Lozano&quot;;
}

int main(){
int select;
char quit;
loadPrescriptions();
while(1){ //forever
cout << &quot;Enter a prescription ID\n&quot;;
cin >> select;
cout << &quot;You are looking for:\n&quot;;
cout << pres[select].c_str() << endl;
cout << &quot;Do again?\n&quot;;
cin >> quit;
if(quit=='q'||quit=='Q'){
break;
}
}
return(0);
}

It compiles perfectly but when I try to compile I get:

Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/string.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
 
Apparently just a Micro$osft problem; bothered to download Borland C++ Builder and it all compiled like a daisy.

I wonder why such a simple project would fake the crap out of VC++.

sigh.

I guess no one out there can help me eh?

dav1d
 
I'm like you, I loathe Microsoft but I have to make money so I program with it.

Your problem was not in your code but the project type. When you started a new project, you should select Win32 Console application, then it will compile and link. Your code looks good.

I can't believe I'm saying this but, give Microsoft another chance. You'll find it much easier in the long run.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top