|
-
Nov 10th, 2001, 08:54 PM
#1
Thread Starter
Fanatic Member
whats wrong here
im trying out CString, just experimenting, and im going crazy. i've look at a couple of sites, and it's correct:
Code:
#include <cstring.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void main(void){
CString s1;
s1= "hello";
printf("%s",s1.Right(1));
}
The Errors:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(7) : error C2065: 'CString' : undeclared identifier
C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(7) : error C2146: syntax error : missing ';' before identifier 's1'
C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(7) : error C2065: 's1' : undeclared identifier
C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(8) : error C2146: syntax error : missing ';' before identifier 's2'
C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(8) : error C2065: 's2' : undeclared identifier
C:\Nabeel\Projects\C++\gfxtest\Cpp1.cpp(8) : error C2228: left of '.Right' must have class/struct/union type
Error executing cl.exe.
Cpp1.exe - 6 error(s), 0 warning(s)
im going crazy over this!
then i tried converting to pointers, and still the same errors
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Nov 10th, 2001, 09:05 PM
#2
PowerPoster
Try declaring the included file as:
VB Code:
#include <cstring>
#include <string>
#include <stdio.h>
#include <stdlib.h>
-
Nov 10th, 2001, 09:14 PM
#3
Thread Starter
Fanatic Member
still the same errors..
i think vc++ is on crack
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Nov 10th, 2001, 09:22 PM
#4
Hyperactive Member
I don't think you can printf a CString.
printf() is meant for null terminated strings.
Meanwhile I am looking the MSDN docs for you.
-
Nov 10th, 2001, 09:32 PM
#5
Thread Starter
Fanatic Member
thanks man,
i dont think thats the problem though., it says its missing a ';', when it isnt...and it says the vars aren't defined
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Nov 10th, 2001, 09:35 PM
#6
Hyperactive Member
You can use CString only in a MFC app.
I think you can only use null terminated strings. I don't think string class in #include<string> provide extracting strings from a string. You got to do it(the extracting) yourself
Meanwhile you can wait patiently for someone to help.
Me no string expert.
-
Nov 10th, 2001, 09:44 PM
#7
Thread Starter
Fanatic Member
only in an MFC app? darn...i dont know MFC yet...gotta start learnin more
--thanks for the help
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Nov 11th, 2001, 06:31 AM
#8
I think you can use CString in console apps by creating a "console app that supports MFC" (in the VC++ wizard). This will add a lot of overhead though.
To use it with printf you would need to explicitely cast to LPCTSTR:
Code:
CString str("Hello, World!");
printf("%s", (LPCTSTR)str.Right(1));
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 11th, 2001, 11:53 AM
#9
Thread Starter
Fanatic Member
yeah i made one that supports MFC and it worked.
ill try that other thingy later..mmm food
thanks
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Nov 11th, 2001, 01:07 PM
#10
Monday Morning Lunatic
If you want to get a substring out of a C++ string, then use the .substr(...) method:
Code:
#include <iostream>
#include <string>
int main() {
string x = "Hello there!";
cout << x.substr(x.length() - 1, 1) << endl;
return 0;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 11th, 2001, 06:58 PM
#11
Thread Starter
Fanatic Member
okiedokie..
i like my CString..it has the Left(), Right() and Mid() funcstions to make to happy
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Nov 12th, 2001, 01:28 PM
#12
Monday Morning Lunatic
You can synthesise Left and Right simply enough, and Mid == substr 
Anyway, why use CString when you can easily use string, and then you've got full standard library compatibility? For example, you can't do this with a CString:
Code:
cout << my_c_string << endl;
...without writing your own inserter.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 12th, 2001, 06:53 PM
#13
Thread Starter
Fanatic Member
do u have any tutorials? i'm willing to learn it...
thanks
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Nov 13th, 2001, 12:12 PM
#14
Monday Morning Lunatic
What's to learn? 
Code:
string x = "Hello";
string y = x + " " + "World!";
string z = string("This ") + x + " is an example";
For z, note that the first This needs to be inside a string constructor, otherwise when the compiler resolves the right hand side it tries to add two pointers together, which is illegal. Forcing it into a string makes it all resolve properly 
And then you've got .substr, which is like Mid().
There's no "Format" like with CString, but you can synthesise it easily enough using vsnprintf. I don't have the code at work, but when I get home if you've replied by then I can send it.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 13th, 2001, 05:08 PM
#15
Thread Starter
Fanatic Member
well the string things i needed/wanted were like "Left", and "Right"
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Nov 13th, 2001, 05:13 PM
#16
Monday Morning Lunatic
That's my point, they're simply applications of Mid or substr.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 14th, 2001, 11:27 AM
#17
Thread Starter
Fanatic Member
i was wondering though,
is there a tutorial? im playing around with string.h now..
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Nov 14th, 2001, 12:41 PM
#18
Monday Morning Lunatic
Ah. string.h != string.
string.h contains the C string handling functions, which you're likely to need a tutorial for (or just look at the MSVC docs). string has the C++ Standard Library's string class, and that's pretty easy to use.
Actually, the MSVC docs have info on the string class as well - they tell you everything you need to know.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
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
|