West Coast Connection Forum

Lifestyle => Tha G-Spot => Topic started by: ::Mr. Hahn:: on March 19, 2005, 06:44:15 PM

Title: c++ Help please anyone! Urgent~
Post by: ::Mr. Hahn:: on March 19, 2005, 06:44:15 PM
Hey guys,

Anyone know much about structs or passing variables to const?

I need to pass a user defined string to a function to process the string..

However, the variable in the function is defined as a const, so i dont know what to do...

Please help me..

const int MAXLINES = 500;            // Maximum number of lines of text
const string PUNCTUATION = ",.;:()"; // Punctuation characters
const string SPACE = " \t\n";        // Space characters

struct Text
{
       string lines[MAXLINES];       // Text lines
       int lastLine;                 // Index of the last line with text.
                                     // If there is no text, lastline < 0
};

void tokenise (const Text &text,
               int &countPunctuation,
               int &countWords,  int &countOther,
               Text &tokens)
{

}     

The string entered by the user in the main function has to go to:

"const Text &text"

However, when i go

cin >> text;

It doesnt work..

Idea's?
Title: Re: c++ Help please anyone! Urgent~
Post by: Da WCC Hopar! on March 19, 2005, 07:20:26 PM
i dont have single clue on wat u just said ive worked wit c++ before and neva go to far on it
Title: Re: c++ Help please anyone! Urgent~
Post by: ::Mr. Hahn:: on March 19, 2005, 07:32:24 PM
its cool, thx for like..replying though!~
Title: Re: c++ Help please anyone! Urgent~
Post by: Suga Foot on March 20, 2005, 01:21:32 AM
:banana_llama:
Title: Re: c++ Help please anyone! Urgent~
Post by: Don Seer on March 20, 2005, 01:43:39 AM

uh dude...

const means dont touch....


remove the const from your parameter being passed in..

btw.. i've been coding c++ for over 10 years now.. i've been at my current job doing it since mid '96.. and could prog in it for a few years before that..


also.. what are thsoe & things for?


if you mean to modify the variables inside the function.. i'd do it like this...


typedef struct _tag_Text
{
       string lines[MAXLINES];       // Text lines
       int lastLine;                 // Index of the last line with text.
                                     // If there is no text, lastline < 0
} MY_TEXT_TYPE, *PMY_TEXT_TYPE;



void tokenise (PMY_TEXT_TYPE pText,
               int  *pnCountPunctuation,
               int  *pnCountWords,  int *pnCountOther,
               PMY_TEXT_TYPE pTokens)
{

}     




holla..
Title: Re: c++ Help please anyone! Urgent~
Post by: ::Mr. Hahn:: on March 20, 2005, 02:23:04 AM
i wish it were that simple.

However, thats defined in the header file and we are not allowed to change that struct/function.

We must use it.

We are also not allowed to use pointers to get around the const...sigh...

I heard its got something to do with inputting it through the text.lines[] because its a string array and u use some sort of loop to enter in the data. Then pass it to tokenise..

How do i do that?
Title: Re: c++ Help please anyone! Urgent~
Post by: Don Seer on March 20, 2005, 11:18:40 AM
silly question what is "it doesnt work?" doesnt build?


should it be

cin >> text.lines;

or

cin >> text->lines;

Title: Re: c++ Help please anyone! Urgent~
Post by: boycriedwolf619 on March 20, 2005, 06:16:16 PM
h

also.. what are thsoe & things for?

that symbol means pass by reference