I am trying to use std::vector in qt, but I seem to get some errors, When ever I include the vector header and compile the below code, I get a big list of errors but when I remove the vector header and compile the same code it works fine.
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
std::cout<<"Vector"<<std::endl;
return 0;
}
The beginning and the end of the build log:
12:03:19: Running steps for project vector...
12:03:19: Configuration unchanged, skipping qmake step.
12:03:19: Starting: "/usr/bin/make"
g++ -c -pipe -g -Wall -W -fPIE -I../../Qt/5.3/gcc/mkspecs/linux-g++ -I../vector -I. -o main.o ../vector/
main.cpp
In file included from ../vector/main.cpp:2:0:
./vector:1:1: error: stray '\177' in program
./vector:1:1: error: stray '\1' in program
./vector:1:1: error: stray '\1' in program
./vector:1:1: error: stray '\1' in program
./vector:1:8: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\2' in program
./vector:1:18: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\3' in program
./vector:1:20: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\1' in program
./vector:1:22: warning: null character(s) ignored [enabled by default]
./vector:1:1: error: stray '\205' in program
./vector:1:1: error: stray '\4' in program
./vector:1:1: error: stray '\10' in program
./vector:1:30: warning: null character(s) ignored [enabled by default]
[...]
./vector:115:880: warning: null character(s) ignored [enabled by default]
./vector:115:886: warning: null character(s) ignored [enabled by default]
In file included from ../vector/main.cpp:2:0:
File: /home/sanjayan/Documents/qt_vector_errors Page 76 of 76
./vector:1:2: error: 'ELF' does not name a type
In file included from ../vector/main.cpp:2:0:
./vector:28:655: error: 'j' does not name a type
In file included from ../vector/main.cpp:2:0:
./vector:61:28: error: expected declaration before '}' token
make: *** [main.o] Error 1
12:03:22: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project vector (kit: Desktop Qt 5.3 GCC 32bit)
When executing step 'Make'
12:03:22: Elapsed time: 00:03.
I hope the provided information's is sufficient for my query.
I had the same problem like you just now. I write a C++ program named vector.cc
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout << "hello" << endl;
return 0;
}
Compilation can pass for the first time (use g++ vector.cc -o vector, creates an executable file named vector), and then any program include the sentence #include vector will face the problems as you said.
The basic reason is the vector file, if the executable file (named "vector") is deleted, everything will be OK.
I hope my answer can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With