return is empty

Mar 31, 2012 at 9:52am

The following code compilies correctly, but does not reurn the string. Seems to be empty.

Probably something obvious, but I can't see it.

Please can anyone help. Thank you.



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
27
28
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
using std::string;

int _tmain(int argc, _TCHAR* argv[])

{
string bigstring; string strFunct;

bigstring = strFunct;
					
cout << bigstring << endl;


cout << "Done\n";
 system("pause");

	return 0;
}


  string strFunct()
{
   return "ooooooooooooooooooo";
}
Mar 31, 2012 at 10:37am
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
27
28
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//using std::string;

int _tmain(int argc, _TCHAR* argv[])

{
string bigstring;// string strFunct;

bigstring = strFunct();
					
cout << bigstring << endl;


cout << "Done\n";
 system("pause");

	return 0;
}


  string strFunct()
{
   return "ooooooooooooooooooo";
}
Mar 31, 2012 at 10:46am
I have the following error when I try that Breadman:

error C2065: 'strFunct' : undeclared identifier
Mar 31, 2012 at 10:48am
In C++, the compiler must know about a function before you use it. In your code, you are trying to use the function strFunct before you have told the compiler about it.

There are two ways you can tell the compiler about it.

1) Declare the function, using a prototype:
string strFunct();

2) Put the whole definition of the function before the main function.
Mar 31, 2012 at 10:59am
Thats it. Working now.

Thanks for help, and quick responses Breadman and Moschops.
Topic archived. No new replies allowed.