这是代码:
#include <stdlib.h>
#include <iostream>
int main() {
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std:cin >> v1 >> v2;
std::cout << "The sum of " << v1 << "and " v2 << "is " << v1+v2 << std:endl;
return 0;
}
这是错误:
g++ x.cpp
#x.cpp: In function ‘int main()’:
#x.cpp:23:9: error: ‘cin’ was not declared in this scope
#x.cpp:23:9: note: suggested alternative:
#In file included from x.cpp:19:0:
#/usr/include/c++/4.7/iostream:61:18: note: ‘std::cin’
#x.cpp:24:48: error: expected ‘;’ before ‘v2’
我已经更正了代码,有几个错误(这是我的第一次c++经验):
#include <stdlib.h>
#include <iostream>
int main() {
std::cout << "Enter two numbers: " << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1+v2 << std::endl;
return 0;
}