473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pointer troubles

im recently working on a project, where I need to read one line, check it for data, then delete some of the data in the string, im using substr. The problem comes when I have to do it in functions.
sorry if i confuse you, i'll try give a example.
FX.
Expand|Select|Wrap|Line Numbers
  1. int DoSome(string *inp) {
  2. if (inp.substr(0,6)=="myflow") {   // here's my problem, inp only points, and don't got the method substr.
  3. inp = inp.substr(6);
  4. // lot of code here
  5. }
  6. }
  7.  
  8. int main() {
  9.    string hello;
  10.    hello = "myflow123";
  11.    DoSome(&hello);
  12. }
  13.  
  14.  
Sorry its not snips, becusase its too big and this would really simplify it, plus make it faster.

Regards
Oct 8 '06 #1
2 1501
I am not sure if you are saying the it soes not gets substr method of std::string class , but effect you are trying to achive can be done by

Expand|Select|Wrap|Line Numbers
  1. int DoSome(string *inp) {
  2. if ((*inp).substr(0,6)=="myflow") {   // here's my problem, inp only points, and don't got the method substr.
  3. (*inp) = (*inp).substr(6);
  4. // lot of code here
  5. }
  6. return (0);
  7. }
  8.  
  9. int DoSome(string &inp) {
  10. if (inp.substr(0,6)=="myflow") {   // here's my problem, inp only points, and don't got the method substr.
  11.  inp = inp.substr(6);
  12. // lot of code here
  13. }
  14. return (0);
  15. }
  16.  
  17.  
  18. int main() {
  19.    string hello;
  20.    hello = "myflow123";
  21.    std::cout<<" Before hello is >>"<<hello<<"<<\n";
  22.    DoSome(&hello);
  23.    std::cout<<" After hello is >>"<<hello<<"<<\n";
  24.  
  25.    string junk;
  26.    junk = "myflow123";
  27.    std::cout<<" Before junk is >>"<<junk<<"<<\n";
  28.    DoSome(junk);
  29.    std::cout<<" After junk is >>"<<junk<<"<<\n";
  30.  
  31.  
  32. }
Code you gave takes a poiter as input and you are using . operator , which will give you compile time errors. You can modify it as above or the best would be use references like

Expand|Select|Wrap|Line Numbers
  1. int DoSome(string &inp) {
  2. if (inp.substr(0,6)=="myflow") {   // here's my problem, inp only points, and don't got the method substr.
  3.  inp = inp.substr(6);
  4. // lot of code here
  5. }
  6. return (0);
  7. }
Oct 9 '06 #2
Thanks.
Thats exactly what I needed :D
Now my project finaly can continue

regards
Oct 9 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Newsgroup - Ann | last post by:
Gurus, I have the following implementation of a member function: class A { // ... virtual double func(double v); void caller(int i, int j, double (* callee)(double)); void foo() {caller(1,...
2
by: Bj?rn Toft Madsen | last post by:
Hi all, The network library I use communicates with my app using a callback function. This callback function is called with the type of message, a void pointer to he actual message and a user...
3
by: mandatory | last post by:
hi, i would like to pass a pointer to a thread function to a class. The function in my code that i would like to get the address of, and pass it to a class function is: DWORD...
3
by: Bruno van Dooren | last post by:
Hi All, i have some (3) different weird pointer problems that have me stumped. i suspect that the compiler behavior is correct because gcc shows the same results. ...
16
by: forester | last post by:
lets say its common situation when object have subobjects in container and receives callbacks from contained items. and object want to move objects in containers on signal(callback). iterator is...
19
by: Sergey Koveshnikov | last post by:
Hello, If my function return a pointer on a memory area, where do I free it? e.x.: char *foo() { char *p; p = malloc(10); strcpy(p, "something"); return(p); }
1
by: Peter Gloor | last post by:
Hello NG, I have a mirror.dll written in C I would like to access from a C# console application. However, I dont't know how to to it. The dll is fairly well documented and I have access to the...
22
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void...
2
by: Jeff | last post by:
Hello- 1. I create a fully complete class (ListClass) 2. I pass the pointer of this class to two (or more) other classes. 3. I get a SEGV while accessing a member of the top level class...
19
by: George | last post by:
Hi all. How can I check and return an error on a constructor that receives a pointer as a parameter and the parameter is null. Is there any possibility to return an error? or do I have to create...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.