West Coast Connection Forum
Lifestyle => Tha G-Spot => Topic started 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?
-
i dont have single clue on wat u just said ive worked wit c++ before and neva go to far on it
-
its cool, thx for like..replying though!~
-
:banana_llama:
-
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..
-
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?
-
silly question what is "it doesnt work?" doesnt build?
should it be
cin >> text.lines;
or
cin >> text->lines;
-
h
also.. what are thsoe & things for?
that symbol means pass by reference