|
-
November 28th, 2001, 07:22 PM
#1
using >> operator
How do I write a function, class (not sure what I have to write to use it) so that I can return a value to an array. Example, cin is programmed to use that operator to put a char in or whatever.
How can I make a function that uses that? Just to demonstrate an example, let's say that I have this:
int function(char data[10])
{
strcat(data," bla bla")
return data;
}
this function would not work since c++ is worse then a nazi when it comes to arrays. Is there a way I can get data using the >> operator? This will help me allot since I have allot of functions I want to write that could use this. Thanks!
-
November 29th, 2001, 02:50 AM
#2
Re: using >> operator
Frankly didn't get why you need a >> operator, may be just you need to use this approach:
#include <stdio.h>
#include <string.h>
char* f(char a[])
{
strcat(a, "Appended String\n");
return a;
}
int main()
{
char a[128] = "Initial String\n";//large
printf(a);
printf(f(a));
return 0;
}
Please - rate answer if it helped you
It gives me inspiration when I see myself in the top list =)
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
[email protected] | ICQ:57404554 | http://soukhov.com
Russian Software Developer Network http://rsdn.ru
-
November 30th, 2001, 11:24 PM
#3
Re: using >> operator
I want to be able to use this way since I can get arrays very quickly once I write a class that can do whatever I want it to do. Instead of going trough all the pointer stuff and return special data types to be able to use more then one char.
I remembering replying to this for some reason but there's none shown to it so I must of dreamed of it or something!(I think I'm too much on the computer if I start getting dreams like that!) Unless I din't notice and typed it in the e-mail... not in my sent items though. hmm, mistery .
-
December 3rd, 2001, 11:32 AM
#4
Re: using >> operator
you can use ostrstream class.
Then you can concatenate a string with << (not >>
So you can do:
void function( std: strstream& os )
{
os << " bla bla";
}
You can use this to stream in formatted, the same way as you would any other stream.
of course you could just use std::string with append or += but that would only allow you to concatenate in strings.
Your function, by the way, is wrong in two ways. Firstly your passing of data[10] - should really pass char *data.
Secondly you are returning a char* while your function is declared to return an int.
-
December 3rd, 2001, 11:34 AM
#5
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
|