-6
這裏聲明是代碼:CIN不相剋這個範圍錯誤++
#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;
}
你的編譯器說第23行存在問題。什麼是第23行,你爲什麼期望它工作正確? – djechlin 2013-05-11 12:21:34