![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
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 |
|
|
|
|
|
#2 | |
|
Professional Programmer
|
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:
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! ▄▄▄▄ |
|
|
|
|
|
|
#3 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
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! |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|