我正在学习c++,并决定编写一个小程序来练习变量作用域。问题是,在编译和执行之后,我在Linux上得到了一个不同的(在我看来是错误的)输出,而在windows上一切都是正确的。代码如下:
/*main.cpp*/
#include <iostream>
using namespace std;
extern int x;
int f();
int main() {
cout << " x = " << x << endl;
cout << "1st output of f() "
temp_holder.clear();
temp_holder << n;
n_str = temp_holder.str();
int f = count(n_str.begin(), n_str.end(), a);
这是我的代码,这是g++输出:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/algorithm:63:0,
from trintatres.cpp:5:
/usr/l
我正在尝试在linux (linux Mint8)中运行我的第一个c++程序。我使用的是gcc或g++,两者都有相同的问题:编译器找不到我试图导入的库。
我怀疑我应该复制工作文件夹中的iostream.h文件(我不知道在哪里查找它),将我的文件移动到其他地方进行编译,或者使用某种选项。
谢谢你的建议。
以下是gcc命令、c++代码和错误消息:
gcc -o addition listing2.5.c
。
#include <iostream.h>
int Addition(int a, int b)
{
return (a + b);
}
int main()
{
我已经安装了ligstdc++-4.9-dev和libstdc++-4.9-doc,并且我想通过man扫描c++库的信息,就像C中的样式一样。但是当我运行"man std::iostream“时,我发现一个错误显示man: can't open /usr/share/man/man3/std::basic_iostream.3cxx: No such file or directory。我检查了/usr/share/man/man3/目录,找到了名为std::iostream.3cxx.gz的文件,但为什么我无法获得std::iostream的手册页?uname -a的输出是L
有简单的,没有任何代码的空项目。只是包含。包含linux/netfilter.h导致编译错误:
In file included from ../src/main.cpp:2:0:
/usr/include/linux/netfilter.h:65:17: error: field ‘in’ has incomplete type
/usr/include/linux/netfilter.h:66:18: error: field ‘in6’ has incomplete type
正如你在这个简单的项目中看到的,我有2个includes,如果我删除了iostream include,我会得到
我不能再和gcc合作了。
使用gcc -o run mytest.cpp,给出:
mytest.cpp:12:9: error: expected ‘;’ at end of member declaration
mytest.cpp:12:14: error: expected unqualified-id before ‘;’ token
mytest.cpp: In constructor ‘matrix::matrix()’:
mytest.cpp:23:26: error: invalid conversion from ‘int**’ to ‘int’ [-fpermissive]
我的代码在visual studio和Linux中运行得很好,但在Linux中运行时遇到了问题。
这个函数是关于一个带有头文件的动态数组。
当我输入数字N时,它打印2到N之间的质数
输出:
当我使用Linux时,我只能得到10以下的质数。
相同的代码但不同的结果!
请告诉我怎样才能把它修好。
这是函数的一部分:
#include <iostream>
#include "sieve.h"
#include <cstring>
using namespace std;
//prints all the prime numbers between 2 a
我试图使用ld直接链接来隔离构建问题。
当我包含/usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so时,我会遇到一些问题:
ac-aaa.o: In function `__static_initialization_and_destruction_0':
/usr/include/c++/4.7/iostream:75: undefined reference to `__dso_handle'
ac-callback.o: In function `__static_initialization_and_destruction_0
#include <iostream>
using namespace std;
int main( int argc, char *argv[])
{
cout << "Hello\nWorld";
}
D:\test>hw |od -c
0000000 H e l l o \r \n W o r l d
0000014
为什么在windows中注入额外的\r (在linux上不会发生)?
C和C++程序不在Angstrom上编译
C Progam (board.c):
#include<stdio.h>
void main(){
printf("hello world");
}
在Angstrom终端上编译C程序
root@pldek-beagle:~/Comparison# gcc board.c -o board
/usr/lib/gcc/arm-angstrom-linux-gnueabi/4.7.3/../../../../arm-angstrom-linux-gnueabi/bin/ld: this linker was not c
在我的centos7.0系统中,当我用g++ test.cpp -o编译代码时,输出是"is linux system“。
使用g++ test.cpp -std=c++11 -o编译测试时,输出为"is not linux system“
为什么在c11中编译器的默认宏发生了变化?
test.cpp
#include <iostream>
using namespace std;
int main(){
#ifdef linux
cout<<"is linux system\n";
#else
如何在C++11中输出enum class的值?在C++03中是这样的:
#include <iostream>
using namespace std;
enum A {
a = 1,
b = 69,
c= 666
};
int main () {
A a = A::c;
cout << a << endl;
}
在c++0x中,此代码不能编译
#include <iostream>
using namespace std;
enum class A {
a = 1,
b = 69,
c= 666
};