Hey guys, im just learning C++ and i really want to learn it, but im having some compiling errors and i've looked around and i dont know what else to do. So i was hoping one of you guys could help me out. so this is my code: Code: #include <iostream> int main() { int integer1, integer2, sum; std::cout << "Enter first integer\n"; std::cin >> integer1; std::cout << "Enter second integer\n"; std::cin >> integer2; sum = integer1 + integer2 std::cout << "Sum is " << sum << std::endl; return 0; } Its pretty simple enough, and i know what its supposed to do, but its not becuase its not compiling. These are the errors i get when i compile and try to run the file: Code: c:\users\bioshock\documents\c++\untitled1.cpp: In function `int main()': c:\users\bioshock\documents\c++\untitled1.cpp:12: use of namespace `std' as expression c:\users\bioshock\documents\c++\untitled1.cpp:12: parse error before `::' Im not really sure what that meant, so any help would be nice. Thanks.
first sol : Code: #include <iostream.h> int main() { int integer1, integer2, sum; cout << "Enter first integer\n"; cin >> integer1; cout << "Enter second integer\n"; cin >> integer2; sum = integer1 + integer2; cout<<"Sum is " <<sum<< endl; return 0; } second solution: Code: #include <iostream> using namespace std; int main() { int integer1, integer2, sum; std::cout << "Enter first integer\n"; std::cin >> integer1; std::cout << "Enter second integer\n"; std::cin >> integer2; sum = integer1 + integer2; std::cout<< "Sum is " << sum << endl; return 0; }
Oh thanks for the reply's and sorry about having it in the wrong section. I put it in there becuase i thought you couldnt ask questions in the regular programming sections.
You are not suppose to use iostream.h in C++. If you dont want to use std:: again and again then this would be a better solutio Code: using std::cout; using std::endl;
your statement std::cout << "Enter first integer\n"; is wrong. Because the keyword :: is the scope resolution key word. here is incorrect. you should remove it from here.
Please dont spread wrong information. First :: is not a keyword it is a scope resolution operator. Second first verify your post with any good C++ compiler, if you dont have access to any then check your code with online C++ compiler from here http://www.comeaucomputing.com/tryitout/ And here is from latest draft of C++ standard Section 3.3.5.2
yes, you are right zamjad. I have write it by mistake. Yes it is not keyword it is scope resolution operator. sorry for that mistake.