how to include C++ header files when using Forte 6 C++ compiler?

how to include C++ header files when using Forte 6 C++ compiler?

Post by Yingxiang W » Sun, 09 Dec 2001 00:58:51



Hi, everyone,

We just installed Forte 6 and are testing its C++ compiler. We got following errors while trying to compile a small
code:

#include <iostream>
#include <string>

main()
{
      string C;
      cout << "hello\n";
      cin >> C;
      cout << "you typed: " << C << endl;

Quote:}

"testC.C", line 7: Error: string is not defined.
"testC.C", line 8: Error: cout is not defined.
"testC.C", line 9: Error: cin is not defined.
"testC.C", line 10: Error: cout is not defined.
"testC.C", line 10: Error: endl is not defined.
5 Error(s) detected.
-----------------------------------------------

If we use iostream.h, errors for cout,cin, and endl are gone. But undefined "string" error is always there no matter
whether <string> or <string.h> is used.

Any suggestions about how to include the header files?

Thanks for any help!

Wu

 
 
 

how to include C++ header files when using Forte 6 C++ compiler?

Post by Toomas Soom » Sun, 09 Dec 2001 03:52:34



> Hi, everyone,

> We just installed Forte 6 and are testing its C++ compiler. We got following errors while trying to compile a small
> code:

> #include <iostream>
> #include <string>

> main()
> {
>       string C;
>       cout << "hello\n";
>       cin >> C;
>       cout << "you typed: " << C << endl;
> }

> "testC.C", line 7: Error: string is not defined.
> "testC.C", line 8: Error: cout is not defined.
> "testC.C", line 9: Error: cin is not defined.
> "testC.C", line 10: Error: cout is not defined.
> "testC.C", line 10: Error: endl is not defined.
> 5 Error(s) detected.
> -----------------------------------------------

> If we use iostream.h, errors for cout,cin, and endl are gone. But undefined "string" error is always there no matter
> whether <string> or <string.h> is used.

> Any suggestions about how to include the header files?

yes, cin and cout will need iostream.h but string is defined in
namespace std, so you need declare C as std::string C;

toomas
--
Is truth not truth for all?
                -- Natira, "For the World is Hollow and I have Touched
                   the Sky", stardate 5476.4.

 
 
 

how to include C++ header files when using Forte 6 C++ compiler?

Post by Paul Flo » Sun, 09 Dec 2001 07:08:16



>Hi, everyone,

>We just installed Forte 6 and are testing its C++ compiler. We got following errors while trying to compile a small
>code:

Forte 6 is more or less ISO/ANSI C++. As such, all of the standard
libraries are placed in the namespace "std". To use them, you either
have to declare that you are using "std" globally

using namespace std;

or on a case by case basis

using std::cout;

or at the point of use

std::cout << "Shwmae, Byd!" << std::endl;

A bientot
Paul
--
Paul Floyd                 http://paulf.free.fr (for what it's worth)

What happens if you have lead in your pants as well as lead in your pencil?