|
|
|
|
#1 |
|
New Member
Join Date: Mar 03
Location: England
Posts: 13
![]() |
Mid$ - C++ equivalent - RESOLVED
Hi,
Does anyone know if there exists a C++ function equivalent of the VB Mid$. I have written my own version, but it keeps on adding extra chars on the end of my char *. Cheers
Last edited by VisBeg; Aug 15th, 2003 at 08:56 AM. |
|
|
|
|
|
#2 |
|
The Devil
Join Date: Aug 00
Location: Quetzalshacatenango
Posts: 9,091
![]() ![]() ![]() |
http://www.vbforums.com/forumdisplay.php?s=&forumid=9
Search the C++ forum. It has been asked several times. And try to keep all C/C++ related topics in there, as well.
__________________
Laugh, and the world laughs with you. Cry, and you just water down your vodka. Take credit, not responsibility |
|
|
|
|
|
#3 |
|
New Member
Join Date: Mar 03
Location: England
Posts: 13
![]() |
Cheers....but it is as related to VB as C++!
|
|
|
|
|
|
#4 | |
|
Monday Morning Lunatic
Join Date: Mar 00
Location: Mashin' on the motorway
Posts: 8,169
![]() |
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s("counterproductive");
cout << s.substr(4, 10) << endl;
}
__________________
Quote:
|
|
|
|
|
|
|
#5 |
|
New Member
Join Date: Mar 03
Location: England
Posts: 13
![]() |
Excellent stuff, I'll give it a go.
Cheers! |
|
|
|
|
|
#6 |
|
New Member
Join Date: Mar 03
Location: England
Posts: 13
![]() |
Thanks for the suggestion, but couldn't get that method to work. Managed to solve the problem using:
char* result = strtok(char * searchString, char* delimiter)
|
|
|
|
|
|
#7 | |
|
Monday Morning Lunatic
Join Date: Mar 00
Location: Mashin' on the motorway
Posts: 8,169
![]() |
That's C not C++, and I would *very* strongly recommend against the use of strtok unless you really know what you're doing.
What wouldn't work about my method? That's the standard method with C++ strings.
__________________
Quote:
|
|
|
|
|
|
|
#8 |
|
New Member
Join Date: Mar 03
Location: England
Posts: 13
![]() |
I keep on getting the error message :
"E2294 Structure required on left side of . or .*" It highlights the substr line. You will have to excuse me, I am new to the world of C and C++. Here is the code that I am using if it helps: char * getNoOfFiles(char * fheader) { char *noOfFiles; noOfFiles = fheader.substr(1, 1); return noOfFiles; } Thanks for the help. p.s. whats wrong with strtok? |
|
|
|
|
|
#9 | |
|
Frenzied Member
Join Date: Jan 00
Location: I live in the 1s and 0s of everyones data streams
Posts: 1,024
![]() |
Quote:
__________________
MSVS 6, .NET & .NET 2003 Pro I HATE MSDN with .NET & .NET 2003!!! Check out my sites: http://www.filthyhands.com http://www.techno-coding.com |
|
|
|
|
|
|
#10 | |
|
Monday Morning Lunatic
Join Date: Mar 00
Location: Mashin' on the motorway
Posts: 8,169
![]() |
strtok is arcane, changes the input, and is non-reentrant. The latter is only important if you're using multiple threads.
.substr is for strings, not character pointers. You're doing all your work here in C, not C++. Use strings instead of char* pointers.
__________________
Quote:
|
|
|
|
|
|
|
#11 | |
|
Kitten
Join Date: Aug 01
Location: In a microchip!
Posts: 11,594
![]() ![]() ![]() ![]() ![]() ![]() |
Quote:
Sorry for the rant. I'm in a bad mood.
__________________
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. |
|
|
|
|
|
|
#12 |
|
New Member
Join Date: Mar 03
Location: England
Posts: 13
![]() |
The reason I am using the 'old char *' stuff, is because I am having to communicate with a WIN CE device over a serial link. This means using some of the old cruddy methods, (as far as I can figure out anyway!)
Cheers for all of the suggestions.
|
|
|
|
|
|
#13 | |
|
Monday Morning Lunatic
Join Date: Mar 00
Location: Mashin' on the motorway
Posts: 8,169
![]() |
If the functions you're using require a const char* with the data to send, just use string::c_str() to access it. Much better to use the normal strings for any processing work.
__________________
Quote:
|
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|