Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 22nd, 2006, 12:08 PM   #1
Kilo
Expert Programmer
 
Kilo's Avatar
 
Join Date: Nov 2005
Location: In Pink Clam?
Posts: 542
Rep Power: 0 Kilo is an unknown quantity at this point
Send a message via AIM to Kilo
strcat() && char array[10] && stupid!

I hate my life...

Im havig some issues with adding strings together.. i do not want to use a char array! i want to add 2 actual strings together!

my code
void Engine::AddError(bool lineAdd, int lineNum, std::string error)
{
	std::string s_tempError;

	if(lineAdd == true)
	{
		strcat(s_tempError, "[LINE#");
	}

	strcat(s_tempError, (char)lineNum);

	strcat(s_tempError, error); 

	s_errorArray.push_back(s_tempError);
}

the errors:

1>------ Build started: Project: SED, Configuration: Debug Win32 ------
1>Compiling...
1>SED.cpp
1>c:\documents and settings\knowell\my documents\visual studio 2005\projects\sed\sed\sed.cpp(38) : error C2664: 'strcat' : cannot convert parameter 1 from 'std::string' to 'char *'
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\documents and settings\knowell\my documents\visual studio 2005\projects\sed\sed\sed.cpp(41) : error C2664: 'strcat' : cannot convert parameter 1 from 'std::string' to 'char *'
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\documents and settings\knowell\my documents\visual studio 2005\projects\sed\sed\sed.cpp(43) : error C2664: 'strcat' : cannot convert parameter 1 from 'std::string' to 'char *'
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\documents and settings\knowell\my documents\visual studio 2005\projects\sed\sed\sed.cpp(74) : warning C4018: '<=' : signed/unsigned mismatch
1>c:\documents and settings\knowell\my documents\visual studio 2005\projects\sed\sed\sed.cpp(95) : warning C4018: '<=' : signed/unsigned mismatch
1>c:\documents and settings\knowell\my documents\visual studio 2005\projects\sed\sed\sed.cpp(115) : warning C4018: '<=' : signed/unsigned mismatch
1>Build log was saved at "file://c:\Documents and Settings\knowell\My Documents\Visual Studio 2005\Projects\SED\SED\Debug\BuildLog.htm"
1>SED - 3 error(s), 3 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
__________________
"When in Rome, Do as the Romans Do"
"Beauty is in the eye of the BEER holder"
"Save your breath your going to need it for your blow up doll later"

SearchLores.org
Kilo is offline   Reply With Quote
Old May 22nd, 2006, 12:12 PM   #2
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
I just threw this together real quick.

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    string hel, lo;
    hel = "hel";
    lo = "lo";

    hel+=lo;
    cout << hel;
    return 0;
}

It explains itself, so I'll just leave it at that.
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old May 22nd, 2006, 12:15 PM   #3
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4 Jessehk is on a distinguished road
strcat() is only used for char arrays (C-style strings).

Simply use the += operator or std::string::append() to add together std::strings.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old May 22nd, 2006, 12:30 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Take about thirty seconds and distinguish in your mind, forever, the difference between a C-string (null terminated array of char) and a "C++" string, which encapsulates that with methods, hidden and otherwise, that serve you breakfast in bed. It'll save you a lot of time and grief.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC