Program not doing the right thing ... it is failing to output!!!

Apr 13, 2012 at 2:45am
Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;
void otherfunc(short* ref);
struct methods
{
    string input;
}; methods M;
int main()
{
    bool gorun = 1;
    while(gorun)
    {
    short pointee = 20;
    short *pointer = &pointee;
    otherfunc(pointer);
}
}
void otherfunc(short* ref)
{
    methods M;
    string output;
    cin >> M.input;
    cout << ref;
    M.input = output;
    cout << "\n" << output;
}


When you input it is supposed to pass the value of the string to output, which is then output.

It outputs only the memory address passed to the function, but won't output the inputted string's value.

Why?
Apr 13, 2012 at 3:40am
Because assignment works in the other direction
Apr 13, 2012 at 4:53am
I don't understand....
Apr 13, 2012 at 5:20am
You wrote M.input = output;
Which is the wrong way round.
Apr 13, 2012 at 5:26am
In truth, this contains so many mistakes and misconceptions - I would suggest you comment the code so we can see what you think you are doing.
Apr 13, 2012 at 5:28am
I think your making this way too hard. If you need to do that...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

using namespace std;

int main();
{
     string num1
     
     cout << "Enter a number";
     GETLINE (CIN, NUM1);
     //Just use getline (cin, **string**);
     cout << num1
     cin.get();
}
Last edited on Apr 13, 2012 at 5:32am
Apr 13, 2012 at 6:31am
thanks so much the original OP is my other account but for some reason i got banned but thanks the assignment was the wrong way!

thx guys! :D
Topic archived. No new replies allowed.