|
-
April 26th, 2004, 01:14 PM
#16
Originally posted by Guysl
Thanks.
I'm using the same headers but keep getting:
error C2679: binary '<<' : no operator defined....
I have the DX9 SDK installed too, with default project setting
uses its libs, could it be the reason? any idea?
Regards,
Guysl
I get no errors compiling the simple code with the proper headers. Maybe you've trashed (overwritten) your STL version with an older one where iostreams doesn't overload the std::string type, or your directory paths are pointing to this older version.
That's basically the problem with VC++'s "iostream.h" -- it knows nothing about std::string, so there was no operator << written for the VC++'s version "iostream.h".
Regards,
Paul McKenzie
Last edited by Paul McKenzie; April 26th, 2004 at 01:16 PM.
-
April 26th, 2004, 04:52 PM
#17
There must be a problem on your system. It compiles fine in my VC6 too. It's in the standard as well (21.2.2).
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily.
Supports C++ and VB out of the box, but can be configured for other languages.
-
April 26th, 2004, 05:21 PM
#18
Re: Thank everyone
Originally posted by taguato
...
char result[10];
string Str("Hello Gurus, good day!");
int n = 10;
strcpy(result,Str.substr( Str.size() - n , n).c_str());
...
Is there any perticular reason you are using a char[10] and not a std::string?
Code:
std::string Result;
std::string Str("Hello Gurus, good day!");
int n = 10;
Result = Str.substr(Str.size() - n , n);
-
April 26th, 2004, 06:26 PM
#19
Paul and Yves, thanks.
I've reinstalled VC++ , now strings output works fine.
Regards,
Guy
**** **** **** **** **/**
-
April 26th, 2004, 09:48 PM
#20
good question
Why using char[10] and not std::string? well, it´s called inexperience.
I could not get my program to accept any of that sintax. I take it was because I did not include the right headers. The code snipped coming from jlou (I think) might shead some light: I am using <string.h>. I will try the one below.
Thanks again.
Luis
PS: btw: while we are at it, what do I have to include to use the CString class?
#include <iostream>
#include <string>
int main()
{
std::string myString = "Hello World!";
std::cout << myString << std::endl;
}
-
April 26th, 2004, 10:13 PM
#21
A humbling experience...
Hi gurus:
The code snipped, along with the "std::string Mystring" worked like a charm... amazing. Just for you guys to get a good laugh, this is what I have to do to get those darn 10 bytes off the string:
// -----------------------------------------------------------------------------------------
// RightS: Copies the rightmost NumChars characters from the string_in to string_out
// -----------------------------------------------------------------------------------------
void RightS(char*string_in,int NumChars, char*string_out)
{
char temp[80];
int length = strlen(string_in);
int i, start, ctr;
start = length - NumChars;
for (i = 0; i <= NumChars; i = i + 1)
{
ctr = start + i;
temp[i] = string_in[ctr];
}
temp[NumChars+1] = '\0';
strcpy(string_out,temp);
}
You can laugh, no problem. I know it´s bizarre, but.. you know, desperation is the mother of creativity, I guess.
But that little code snipped took it of it elegantly. And yes, it was <string>. the <string.h> it´s for something else... I write off as a good experience.
Thanks again,
Luis
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|