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

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?
Because assignment works in the other direction
I don't understand....
You wrote M.input = output;
Which is the wrong way round.
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.
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
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.