来帮初学者看一小下下哈
来帮菜鸟看一小下下哈!
#include <iostream>
#include <string>
using std::cout;
using std::endl;
int main()
{
string st( "The expense of spirit\n ");
cout < < "The size of " < < st < < "is " < <st.size()
< < "characters,including the newline " < <endl;
return 0;
}
编译错误提示:
--------------------Configuration: Text2 - Win32 Debug--------------------
Compiling...
Text2.cpp
C:\Program Files\我的文档\我的视频\Text2.cpp(9) : error C2065: 'string ' : undeclared identifier
C:\Program Files\我的文档\我的视频\Text2.cpp(9) : error C2146: syntax error : missing '; ' before identifier 'st '
C:\Program Files\我的文档\我的视频\Text2.cpp(9) : error C2065: 'st ' : undeclared identifier
C:\Program Files\我的文档\我的视频\Text2.cpp(10) : error C2228: left of '.size ' must have class/struct/union type
执行 cl.exe 时出错.
Text2.exe - 1 error(s), 0 warning(s)
why?how can i do?
------解决方案--------------------
using std::cout;
using std::endl;
把这两句换成
using namespace std;
#include <iostream>
#include <string>
using std::cout;
using std::endl;
int main()
{
string st( "The expense of spirit\n ");
cout < < "The size of " < < st < < "is " < <st.size()
< < "characters,including the newline " < <endl;
return 0;
}
编译错误提示:
--------------------Configuration: Text2 - Win32 Debug--------------------
Compiling...
Text2.cpp
C:\Program Files\我的文档\我的视频\Text2.cpp(9) : error C2065: 'string ' : undeclared identifier
C:\Program Files\我的文档\我的视频\Text2.cpp(9) : error C2146: syntax error : missing '; ' before identifier 'st '
C:\Program Files\我的文档\我的视频\Text2.cpp(9) : error C2065: 'st ' : undeclared identifier
C:\Program Files\我的文档\我的视频\Text2.cpp(10) : error C2228: left of '.size ' must have class/struct/union type
执行 cl.exe 时出错.
Text2.exe - 1 error(s), 0 warning(s)
why?how can i do?
------解决方案--------------------
using std::cout;
using std::endl;
把这两句换成
using namespace std;