为什么还是不能编译(简单) [英] Why still can't compile (simple)

查看:63
本文介绍了为什么还是不能编译(简单)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么仍然无法编译(简单)


大家好


我无话可说,代码仍然不能是complie,'问题在哪里?


============================= ============

//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 ="这是测试字符串" ;;


tmp_vs_<< i_a<< str_tmp;


返回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>


无效

VirtualScreen ::

printf_char(std :: string ch)

{

fprintf(stdout,ch.c_str());

}

VirtualScreen&运营商LT;< (VirtualScreen& p_vs,std :: string p_String)

{

std :: stringstream Temp;

Temp<< p_String;

p_vs.print_char(Temp.str());

返回p_vs;

}


VirtualScreen&运营商LT;< (VirtualScreen& p_vs,int p_Number)

{

std :: stringstream Temp;

Temp<< p_Number;

p_vs.print_char(Temp.str());

返回p_vs;

}


===========================================

请给complie命令字符串

我用

" gcc -o test test.cpp virtual_screen.cpp -lddc ++"

" gcc -o test test.cpp virtual_screen.cpp"


我很难过...... :(


非常感谢

很多


key9

解决方案

key9写道:


为什么仍然无法编译(简单)


大家好


我无话可说,代码仍然无法编译,其中''s

问题?



你应该知道_where_它是(即使你不知道_what_它是。)如果编译器没有告诉你,我会非常惊讶。所以请复制错误

来自编译器的消息发布并在

中标记它所引用的代码。


我使用

" ; gcc -o test test.cpp virtual_screen.cpp -lstdc ++"

" gcc -o test test.cpp virtual_screen.cpp"



您应该使用g ++ for C ++代码而不是明确链接libstdc ++。


对不起那:这是输出

我不知道为什么这里有太多不可读的字符,无论是在tty还是

控制台


g ++ -o test test.cpp virtual_screen.cpp



virtual_screen.h:11:错误: a?~std :: stringa?T尚未声明

test.cpp:7:错误:新类型可能未在返回类型中定义

test.cpp :7:注意:(定义

a后可能缺少分号?~VirtualScreena?T)

test.cpp:7:错误:两种或多种数据类型在宣告?~maina?T?[0m

test.cpp:7:错误:a?〜:: maina?T必须返回?~inject?T?[0m
test.cpp:在函数中?~int main(int,const char **)a?T:

test.cpp:12:错误:a?~stringa?T未在此范围内声明

test.cpp:12:错误:预期`;''在?~str_tmpa?T之前?[0m

test.cpp:14:错误:不匹配?〜运算符<< a?T in a?〜 tmp_vs_<<

i_aa?T?[0m

test.cpp:14:错误:a?~str_tmpa?T未在此范围内声明

virtual_screen.cpp:4:21:错误:sstream.h:没有这样的文件或目录

virtual_screen.h:11:错误:a?~std :: stringa?T有尚未宣布

virtual_screen.cpp:8:错误:声明中有两种或更多数据类型

a?~printf_chara?T?[0m

virtual_screen.cpp:8:错误:a?~VirtualScreen VirtualScreen :: printf_chara?T

不是?〜类VirtualScreena的静态成员?T?[0m

virtual_screen.cpp:8:错误:a?~stringa?T不是?~stda?T的成员?[0m

virtual_screen.cpp:9:错误:预期a?〜, a?T或?〜; a?T之前?〜{a?T

令牌

virtual_screen.cpp:15:错误:a?~std :: stringa?T尚未宣布

virtual_screen.cpp:在函数中?~VirtualScreen& operator<<(VirtualScreen&,

int)a?T:

virtual_screen.cpp:18:错误:a?~stringstreama?T不是<的成员br />
a?~stda?T?[0m

virtual_screen.cpp:18:错误:预期`;''之前?~T坦a?T?[0m

virtual_screen.cpp:19:错误:a?~T坦a?T未在此范围内声明

virtual_screen.cpp:20:错误:a?~class VirtualScreena?T没有成员名为

a?~print_chara?T?[0m

virtual_screen.cpp:在功能中?~VirtualScreen& operator<<(VirtualScreen&,

int)a?T:

virtual_screen.cpp:25:错误:重新定义?~VirtualScreen&

运算符<<(VirtualScreen&,int)a?T?[0m

virtual_screen.cpp:15:错误:a?~VirtualScreen& operator<<(VirtualScreen&,

int)a?T此处定义的

virtual_screen.cpp:29:错误:a?~stringstreama?T不是会员

a?~stda?T?[0m

virtual_screen.cpp:29:错误:预期`;''之前?~T坦a?T?[0m

virtual_screen.cpp:30:错误:a?~T坦a?T未在此范围内声明

virtual_screen.cpp:31:错误:a?~class VirtualScreena?T has没有会员名叫

a?~print_chara?T?[0>

blockquote>

对不起,我想我已经失去了我的刚才介意

我的代码输出后这个

只有2个错误


g ++ -o test test。 cpp virtual_screen.cpp



virtual_screen.h:15:错误:在一个?〜& a?T令牌之前的预期初始化程序

测试。 cpp:在函数中?~int main(int,const char **)a?T:

test.cpp:14:错误:不匹配?〜运算符<< a?T在

a?〜运算符<<(((VirtualS creen&安培;)(&安培; tmp_vs_)),i_a)<< str_tmpa?T?[0m

virtual_screen.h:17:注意:候选人是:VirtualScreen&

operator<<(VirtualScreen&,int)

virtual_screen.h:15:错误:预期的初始化程序在一个?〜& a?T令牌之前


virtual_screen.h

==== ============================

#ifndef VIRTUAL_SCREEN_H

#define VIRTUAL_SCREEN_H

#include< string>

class VirtualScreen

{

public:

void printf_char(std :: string ch);


}


VirtualScreen&运营商LT;< (VirtualScreen& p_vs,std :: string p_String);

//第15行

VirtualScreen&运营商LT;< (VirtualScreen& p_vs,int p_Number); //

第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());

}


/ *样本结束骑* /


VirtualScreen&运营商LT;< (VirtualScreen& p_vs,std :: string p_String)

{

//让终端按原样打印字符串。

std: :stringstream Temp;

Temp<< p_String;

p_vs.printf_char(Temp.str());

返回p_vs;

}

VirtualScreen& ;运营商LT;< (VirtualScreen& p_vs,int p_Number)

{

//将数字转换为字符串并让终端打印

//文本数字的表示。

std :: stringstream Temp;

Temp<< p_Number;

p_vs.printf_char(Temp.str());

返回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 ="这是测试字符串" ;;


tmp_vs_<< i_a<< str_tmp;


返回0;

}



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

解决方案

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.


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: a?~std::stringa?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
a?~VirtualScreena?T)
test.cpp:7: error: two or more data types in declaration of a?~maina?T
test.cpp:7: error: a?~::maina?T must return a?~inta?T
test.cpp: In function a?~int main(int, const char**)a?T:
test.cpp:12: error: a?~stringa?T was not declared in this scope
test.cpp:12: error: expected `;'' before a?~str_tmpa?T
test.cpp:14: error: no match for a?~operator<<a?T in a?~tmp_vs_ <<
i_aa?T
test.cpp:14: error: a?~str_tmpa?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: a?~std::stringa?T has not been declared
virtual_screen.cpp:8: error: two or more data types in declaration of
a?~printf_chara?T
virtual_screen.cpp:8: error: a?~VirtualScreen VirtualScreen::printf_chara?T
is not a static member of a?~class VirtualScreena?T
virtual_screen.cpp:8: error: a?~stringa?T is not a member of a?~stda?T
virtual_screen.cpp:9: error: expected a?~,a?T or a?~;a?T before a?~{a?T
token
virtual_screen.cpp:15: error: a?~std::stringa?T has not been declared
virtual_screen.cpp: In function a?~VirtualScreen& operator<<(VirtualScreen&,
int)a?T:
virtual_screen.cpp:18: error: a?~stringstreama?T is not a member of
a?~stda?T
virtual_screen.cpp:18: error: expected `;'' before a?~Tempa?T
virtual_screen.cpp:19: error: a?~Tempa?T was not declared in this scope
virtual_screen.cpp:20: error: a?~class VirtualScreena?T has no member named
a?~print_chara?T
virtual_screen.cpp: In function a?~VirtualScreen& operator<<(VirtualScreen&,
int)a?T:
virtual_screen.cpp:25: error: redefinition of a?~VirtualScreen&
operator<<(VirtualScreen&, int)a?T
virtual_screen.cpp:15: error: a?~VirtualScreen& operator<<(VirtualScreen&,
int)a?T previously defined here
virtual_screen.cpp:29: error: a?~stringstreama?T is not a member of
a?~stda?T
virtual_screen.cpp:29: error: expected `;'' before a?~Tempa?T
virtual_screen.cpp:30: error: a?~Tempa?T was not declared in this scope
virtual_screen.cpp:31: error: a?~class VirtualScreena?T has no member named
a?~print_chara?T[0


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 a?~&a?T token
test.cpp: In function a?~int main(int, const char**)a?T:
test.cpp:14: error: no match for a?~operator<<a?T in
a?~operator<<(((VirtualScreen&)(& tmp_vs_)), i_a) << str_tmpa?T
virtual_screen.h:17: note: candidates are: VirtualScreen&
operator<<(VirtualScreen&, int)
virtual_screen.h:15: error: expected initializer before a?~&a?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;
}



这篇关于为什么还是不能编译(简单)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆