473,320 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why still can't compile (simple)

Why still can't compile (simple)

Hi all

I have nothing to say , the code still can not be complie, where's problem?

=========================================
//test.cpp
#include <stdio.h>
#include <string.h>
#include "virtual_screen.h"
int main( int argc, const char* argv[] )
{
VirtualScreen tmp_vs_;

int i_a = 100;
string str_tmp = "This is test string";

tmp_vs_ << i_a << str_tmp;

return 0;
}

==========================================
//virtual_screen.h
#ifndef VIRTUAL_SCREEN_H
#define VIRTUAL_SCREEN_H

#include <string.h>

class VirtualScreen
{
public:
void printf_char(std::string ch);
}

#endif //VIRTUAL_SCREEN_H

==========================================
//virtual_screen.cpp

#include <stdio.h>
#include <string.h>
#include "virtual_screen.h"
#include <sstream.h>

void
VirtualScreen::
printf_char(std::string ch)
{
fprintf(stdout,ch.c_str ());
}
VirtualScreen& operator<< (VirtualScreen& p_vs, std::string p_String)
{
std::stringstream Temp;
Temp << p_String;
p_vs.print_char (Temp.str());
return p_vs;
}

VirtualScreen& operator<< (VirtualScreen& p_vs, int p_Number)
{
std::stringstream Temp;
Temp << p_Number;
p_vs.print_char (Temp.str());
return p_vs;
}

===========================================
please give the complie command string
I use
"gcc -o test test.cpp virtual_screen.cpp -lstdc++"
"gcc -o test test.cpp virtual_screen.cpp"

I am sad ......:(

thank you very
much

key9
Sep 13 '06 #1
15 3044
key9 wrote:
Why still can't compile (simple)

Hi all

I have nothing to say , the code still can not be complie, where's
problem?
You should know _where_ it is (even if you don't know _what_ it is). I would
be very surprised if the compiler didn't tell you. So please copy the error
message you got from the compiler into your posting and mark the line in
your code that it refers to.
I use
"gcc -o test test.cpp virtual_screen.cpp -lstdc++"
"gcc -o test test.cpp virtual_screen.cpp"
You should use g++ for C++ code and not link libstdc++ explicitly.

Sep 13 '06 #2
sorry for that: here 's the output
I 've got no idea why here's so much unreadable char , either in tty or
console

g++ -o test test.cpp virtual_screen.cpp
virtual_screen.h:11: error: â?~std::stringâ?T has not been declared
test.cpp:7: error: new types may not be defined in a return type
test.cpp:7: note: (perhaps a semicolon is missing after the definition of
â?~VirtualScreenâ?T)
test.cpp:7: error: two or more data types in declaration of â?~mainâ?T
test.cpp:7: error: â?~::mainâ?T must return â?~intâ?T
test.cpp: In function â?~int main(int, const char**)â?T:
test.cpp:12: error: â?~stringâ?T was not declared in this scope
test.cpp:12: error: expected `;' before â?~str_tmpâ?T
test.cpp:14: error: no match for â?~operator<<â?T in â?~tmp_vs_ <<
i_aâ?T
test.cpp:14: error: â?~str_tmpâ?T was not declared in this scope
virtual_screen.cpp:4:21: error: sstream.h: No such file or directory
virtual_screen.h:11: error: â?~std::stringâ?T has not been declared
virtual_screen.cpp:8: error: two or more data types in declaration of
â?~printf_charâ?T
virtual_screen.cpp:8: error: â?~VirtualScreen VirtualScreen::printf_charâ?T
is not a static member of â?~class VirtualScreenâ?T
virtual_screen.cpp:8: error: â?~stringâ?T is not a member of â?~stdâ?T
virtual_screen.cpp:9: error: expected â?~,â?T or â?~;â?T before â?~{â?T
token
virtual_screen.cpp:15: error: â?~std::stringâ?T has not been declared
virtual_screen.cpp: In function â?~VirtualScreen& operator<<(VirtualScreen&,
int)â?T:
virtual_screen.cpp:18: error: â?~stringstreamâ?T is not a member of
â?~stdâ?T
virtual_screen.cpp:18: error: expected `;' before â?~Tempâ?T
virtual_screen.cpp:19: error: â?~Tempâ?T was not declared in this scope
virtual_screen.cpp:20: error: â?~class VirtualScreenâ?T has no member named
â?~print_charâ?T
virtual_screen.cpp: In function â?~VirtualScreen& operator<<(VirtualScreen&,
int)â?T:
virtual_screen.cpp:25: error: redefinition of â?~VirtualScreen&
operator<<(VirtualScreen&, int)â?T
virtual_screen.cpp:15: error: â?~VirtualScreen& operator<<(VirtualScreen&,
int)â?T previously defined here
virtual_screen.cpp:29: error: â?~stringstreamâ?T is not a member of
â?~stdâ?T
virtual_screen.cpp:29: error: expected `;' before â?~Tempâ?T
virtual_screen.cpp:30: error: â?~Tempâ?T was not declared in this scope
virtual_screen.cpp:31: error: â?~class VirtualScreenâ?T has no member named
â?~print_charâ?T[0

Sep 13 '06 #3
I am sorry , I think I've lost my mind just now
after currect my code to this
only 2 mistake
g++ -o test test.cpp virtual_screen.cpp
virtual_screen.h:15: error: expected initializer before â?~&â?T token
test.cpp: In function â?~int main(int, const char**)â?T:
test.cpp:14: error: no match for â?~operator<<â?T in
â?~operator<<(((VirtualScreen&)(& tmp_vs_)), i_a) << str_tmpâ?T
virtual_screen.h:17: note: candidates are: VirtualScreen&
operator<<(VirtualScreen&, int)
virtual_screen.h:15: error: expected initializer before â?~&â?T token

virtual_screen.h
================================
#ifndef VIRTUAL_SCREEN_H
#define VIRTUAL_SCREEN_H
#include <string>
class VirtualScreen
{
public:
void printf_char(std::string ch);

}

VirtualScreen& operator<< (VirtualScreen& p_vs, std::string p_String);
//line 15

VirtualScreen& operator<< (VirtualScreen& p_vs, int p_Number); //
line 17

#endif //VIRTUAL_SCREEN_H
virtual_screen.cpp
=================================
#include <stdio.h>
#include <string>
#include "virtual_screen.h"
#include <sstream>

class VirtualScreen;

void
VirtualScreen::
printf_char(std::string ch)
{
fprintf(stdout,ch.c_str());
}

/* sample of over ride */

VirtualScreen& operator<< (VirtualScreen& p_vs, std::string p_String)
{
// Let the terminal print the string as it is.
std::stringstream Temp;
Temp << p_String;
p_vs.printf_char (Temp.str());
return p_vs;
}
VirtualScreen& operator<< (VirtualScreen& p_vs, int p_Number)
{
// Convert the number to a string and let the terminal print the
// text representation of the number.
std::stringstream Temp;
Temp << p_Number;
p_vs.printf_char (Temp.str());
return p_vs;
}
test.cpp
=================================
#include <stdio.h>
#include <string>
#include "virtual_screen.h"

int main( int argc, const char* argv[] )
{
VirtualScreen tmp_vs_;

int i_a = 100;
std::string str_tmp = "This is test string";

tmp_vs_ << i_a << str_tmp;

return 0;
}


Sep 13 '06 #4
key9 wrote:
sorry for that: here 's the output
I 've got no idea why here's so much unreadable char , either in tty or
console

>g++ -o test test.cpp virtual_screen.cpp
virtual_screen.h:11: error: â?~std::stringâ?T has not been declared
test.cpp:7: error: new types may not be defined in a return type
test.cpp:7: note: (perhaps a semicolon is missing after the definition of
â?~VirtualScreenâ?T)
test.cpp:7: error: two or more data types in declaration of â?~mainâ?T
test.cpp:7: error: â?~::mainâ?T must return â?~intâ?T
test.cpp: In function â?~int main(int, const char**)â?T:
test.cpp:12: error: â?~stringâ?T was not declared in this scope
test.cpp:12: error: expected `;' before â?~str_tmpâ?T
test.cpp:14: error: no match for â?~operator<<â?T in â?~tmp_vs_ <<
i_aâ?T
test.cpp:14: error: â?~str_tmpâ?T was not declared in this scope
virtual_screen.cpp:4:21: error: sstream.h: No such file or directory
virtual_screen.h:11: error: â?~std::stringâ?T has not been declared
virtual_screen.cpp:8: error: two or more data types in declaration of
â?~printf_charâ?T
virtual_screen.cpp:8: error: â?~VirtualScreen VirtualScreen::printf_charâ?T
is not a static member of â?~class VirtualScreenâ?T
virtual_screen.cpp:8: error: â?~stringâ?T is not a member of â?~stdâ?T
virtual_screen.cpp:9: error: expected â?~,â?T or â?~;â?T before â?~{â?T
token
virtual_screen.cpp:15: error: â?~std::stringâ?T has not been declared
virtual_screen.cpp: In function â?~VirtualScreen& operator<<(VirtualScreen&,
int)â?T:
virtual_screen.cpp:18: error: â?~stringstreamâ?T is not a member of
â?~stdâ?T
virtual_screen.cpp:18: error: expected `;' before â?~Tempâ?T
virtual_screen.cpp:19: error: â?~Tempâ?T was not declared in this scope
virtual_screen.cpp:20: error: â?~class VirtualScreenâ?T has no member named
â?~print_charâ?T
virtual_screen.cpp: In function â?~VirtualScreen& operator<<(VirtualScreen&,
int)â?T:
virtual_screen.cpp:25: error: redefinition of â?~VirtualScreen&
operator<<(VirtualScreen&, int)â?T
virtual_screen.cpp:15: error: â?~VirtualScreen& operator<<(VirtualScreen&,
int)â?T previously defined here
virtual_screen.cpp:29: error: â?~stringstreamâ?T is not a member of
â?~stdâ?T
virtual_screen.cpp:29: error: expected `;' before â?~Tempâ?T
virtual_screen.cpp:30: error: â?~Tempâ?T was not declared in this scope
virtual_screen.cpp:31: error: â?~class VirtualScreenâ?T has no member named
â?~print_charâ?T[0
string.h nor sstream.h are not standard headers

Now you must use string and sstream.

>

Sep 13 '06 #5
key9 wrote:
sorry for that: here 's the output
I 've got no idea why here's so much unreadable char , either in tty or
console
Seems your console doesn't use the same character set as your compiler.
>g++ -o test test.cpp virtual_screen.cpp
virtual_screen.h:11: error: â?~std::stringâ?T has not been declared
Well, the compiler is right. You #included the wrong header. Try <string>
instead of <string.h>.
test.cpp:7: error: new types may not be defined in a return type
test.cpp:7: note: (perhaps a semicolon is missing after the definition of
â?~VirtualScreenâ?T)
test.cpp:7: error: two or more data types in declaration of
â?~mainâ?T test.cpp:7: error: â?~::mainâ?T must return
â?~intâ?T
Those messages probably all result from a missing semicolon at the end of
your class definition in virtual_screen.h. The second one already tells you
exactly that.
test.cpp: In function â?~int main(int, const char**)â?T:
test.cpp:12: error: â?~stringâ?T was not declared in this scope
test.cpp:12: error: expected `;' before â?~str_tmpâ?T
Those have the same reason as the first few messages (and you forgot to use
the std:: prefix for the type on your definition of str_tmp).
test.cpp:14: error: no match for â?~operator<<â?T in â?~tmp_vs_ <<
i_aâ?T
Indeed, you didn't declare that operator anywhwere in your header.
test.cpp:14: error: â?~str_tmpâ?T was not declared in this scope
Another result of the compiler not finding the string class.
virtual_screen.cpp:4:21: error: sstream.h: No such file or directory
The header name you want is <sstring>.

All the other error messages seem to be results from the errors mentioned
above.

Sep 13 '06 #6
Carlos Martinez wrote:
>
string.h nor sstream.h are not standard headers
string.h is a standard header, but it's the wrong one.
Sep 13 '06 #7

key9 wrote:
Why still can't compile (simple)

Hi all

I have nothing to say , the code still can not be complie, where's problem?

=========================================
//test.cpp
#include <stdio.h>
#include <string.h>
#include "virtual_screen.h"
int main( int argc, const char* argv[] )
{
VirtualScreen tmp_vs_;

int i_a = 100;
string str_tmp = "This is test string";
unless virtual_screen.h brings in std::string then you haven't brought
it in at all. You should include <stringnot <string.h>. You should
include <cstdioin preference to <stdio.hbut I don't see why you
need to include that file at all.
tmp_vs_ << i_a << str_tmp;

return 0;
}

==========================================
//virtual_screen.h
#ifndef VIRTUAL_SCREEN_H
#define VIRTUAL_SCREEN_H

#include <string.h>

class VirtualScreen
{
public:
void printf_char(std::string ch);
}

#endif //VIRTUAL_SCREEN_H
You did operator<< with VirtualScreen above but there is no operator<<
declared with a RHS of VirtualScreen and a LHS of int. You define it
later on but you need a prototype.

You should be including <stringnot <string.h>. Your function should
probably take const std::string & as its parameter type but that's not
essential. You might also want to make the function const. (It can't
change the state of VirtualScreen as VirtualScreen doesn't have any
member variables).
==========================================
//virtual_screen.cpp

#include <stdio.h>
#include <string.h>
#include "virtual_screen.h"
#include <sstream.h>
Headers again.
void
VirtualScreen::
printf_char(std::string ch)
{
fprintf(stdout,ch.c_str ());
}
Note that the string could contain sequences like %s or %c in it which
would invoke undefined behaviour as fprintf would look for latter
parameters that aren't there. fputs would be a better option. Why use
printf at all though? What's wrong with cout? Now if you were doing
formatted output I could forgive you for using fprintf, although
boost::format is a good alternative.
VirtualScreen& operator<< (VirtualScreen& p_vs, std::string p_String)
{
std::stringstream Temp;
Temp << p_String;
p_vs.print_char (Temp.str());
return p_vs;
}
Pointless use of stringstream when all you do is convert back to the
string you started off with. You streamed it for practice?
VirtualScreen& operator<< (VirtualScreen& p_vs, int p_Number)
{
std::stringstream Temp;
Temp << p_Number;
p_vs.print_char (Temp.str());
return p_vs;
}
This one does make sense. Note you could make operator<< a template.

Essentially, to get it to compile, use the correct headers and put in a
prototype to your operator << overloads in the header.

Sep 13 '06 #8
key9 a écrit :
I am sorry , I think I've lost my mind just now
after currect my code to this
only 2 mistake
class VirtualScreen
{
public:
void printf_char(std::string ch);

}
A semicolon is needed here.

VirtualScreen& operator<< (VirtualScreen& p_vs, std::string p_String);
//line 15
--
Serge Paccalin
<se************@easyvisio.net>
Sep 13 '06 #9
key9 wrote:
sorry for that: here 's the output
I 've got no idea why here's so much unreadable char , either in tty or
console
Probably colorgcc. The solution would be to install the missing
packages to allow color coded output on the console, but that's
offtopic on this list.
g++ -o test test.cpp virtual_screen.cpp
virtual_screen.h:11: error: â?~std::stringâ?T has not been declared
Let me guess, you've been stuck away on some non c++ island for the
last ten years ;-)

Nowadays we don't use
#include <string.h>
we use
#include <string>

for ALL standard headers. Didn't bother to look at the rest, maybe it's
ok ;-)

Sep 13 '06 #10

Rolf Magnus wrote:
key9 wrote:
virtual_screen.cpp:4:21: error: sstream.h: No such file or directory

The header name you want is <sstring>.
Actually it's <sstream>

Sep 13 '06 #11
"F.J.K." <fe***********@gmail.comwrote in message
news:11**********************@e63g2000cwd.googlegr oups.com...

Nowadays we don't use
#include <string.h>
we use
#include <string>

for ALL standard headers. Didn't bother to look at the rest, maybe it's
ok ;-)

[pjp] No, we use:

-- <string.hto declare the C string functions in the global namespace

-- <cstringto declare the C string functions in namespace std

-- <stringto declare template class basic_string

All are part of Standard C++.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Sep 13 '06 #12
Earl Purple wrote:
>
Rolf Magnus wrote:
>key9 wrote:
virtual_screen.cpp:4:21: error: sstream.h: No such file or directory

The header name you want is <sstring>.
Actually it's <sstream>
Oops... my bad. You're right of course.
Sep 13 '06 #13
P.J. Plauger wrote:
[pjp] No, we use:

-- <string.hto declare the C string functions in the global namespace

-- <cstringto declare the C string functions in namespace std

-- <stringto declare template class basic_string

All are part of Standard C++.
Thanks for clarification. Just out of historical interest. Wasn't there
a time in earliest C++, when including <string.hwould give you class
std::string and including <cstring.hwould give you std::strcat and
it's merry bunch?

Sep 15 '06 #14
P.J. Plauger wrote:
[pjp] No, we use:

-- <string.hto declare the C string functions in the global namespace

-- <cstringto declare the C string functions in namespace std

-- <stringto declare template class basic_string

All are part of Standard C++.
Thanks for clarification. Just out of historical interest. Wasn't there
a time in earliest C++, when including <string.hwould give you class
std::string and including <cstring.hwould give you std::strcat and
it's merry bunch?

Sep 15 '06 #15
In article <11********************@i3g2000cwc.googlegroups.co m>,
fe***********@gmail.com says...

[ ... ]
Thanks for clarification. Just out of historical interest. Wasn't there
a time in earliest C++, when including <string.hwould give you class
std::string and including <cstring.hwould give you std::strcat and
it's merry bunch?
Certainly not with any compiler I ever used, and I rather doubt it
happened with any compiler, period. From the very beginning, C++
coexisted with C, so all the C headers remained nearly intact. The sole
change to most of them was adding extern "C" to the declarations. A few
also had to change a few minor details, such as defining NULL as an
integer type instead of a pointer to void.

I believe the <c*headers were invented by the committee -- no early
compiler I ever used included them at all.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Sep 15 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jordan Willms | last post by:
My xsl stylesheet is as simple as follows: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:ims="http://www.imsglobal.org/xsd/imsmd_v1p2"...
6
by: john a. bailo | last post by:
I have created the world's greatest OSS program. Here it is. I defy you to compile and run it. This will separate the trolls from the zealots. HHAHAHAHAHHAAHAHHAH!!!!!
6
by: surrealtrauma | last post by:
i have a trouble about that: i want to ask user to enter the employee data (employee no., name, worked hour, etc.), but i dont know how to sort the data related to a particular employee as a...
22
by: Qopit | last post by:
Hi there, I'm pretty new to Python and am trying to figure out how to get "will this code compile?"-like code checking. To me this is a pretty basic language/environment requirement, especially...
4
by: Dave Rahardja | last post by:
I have the following program that uses an array of chars to simulate a bit set: --------- // An out-of-bounds exception class BoundsException {}; template <int bits = 1> class Bitset
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
1
by: Nagaraj | last post by:
hi all, I have simple basic c++ program "hello world" which i cant compile on linux system. I have given extension as .C. please tell me how to compile C++ programs on Linux.
1
by: msarora | last post by:
I'm using SimpleTransform.java (renamed as ReceiptTransformer.java for custom use) found in xalan-j_2_7_0 samples directory for transformations in my custom application. The program compiles...
9
by: beet | last post by:
Hi, I am really not good at c/c++. Some simple code.. #include <stdio.h> #include <stdlib.h> #include <math.h> #include "simlibdefs.h"
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.