刚学VC++
#include "STRING.H"
int main(int argc, char* argv[])
{
string s="Hello World!"; printf(s);
return 0;
}
出现错误
--------------------Configuration: Myapp - Win32 Debug--------------------
Compiling...
Myapp.cpp
D:\sssss\Myapp\Myapp.cpp(9) : error C2065: 'string' : undeclared identifier
D:\sssss\Myapp\Myapp.cpp(9) : error C2146: syntax error : missing ';' before identifier 's'
D:\sssss\Myapp\Myapp.cpp(9) : error C2065: 's' : undeclared identifier
D:\sssss\Myapp\Myapp.cpp(9) : error C2440: '=' : cannot convert from 'char [13]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.Myapp.exe - 4 error(s), 0 warning(s)请各位大侠指教!谢谢
#include "STRING.H"
int main(int argc, char* argv[])
{
string s="Hello World!"; printf(s);
return 0;
}
出现错误
--------------------Configuration: Myapp - Win32 Debug--------------------
Compiling...
Myapp.cpp
D:\sssss\Myapp\Myapp.cpp(9) : error C2065: 'string' : undeclared identifier
D:\sssss\Myapp\Myapp.cpp(9) : error C2146: syntax error : missing ';' before identifier 's'
D:\sssss\Myapp\Myapp.cpp(9) : error C2065: 's' : undeclared identifier
D:\sssss\Myapp\Myapp.cpp(9) : error C2440: '=' : cannot convert from 'char [13]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.Myapp.exe - 4 error(s), 0 warning(s)请各位大侠指教!谢谢
pritnf是C的标准库函数,第一个参数只能是字符指针,不可以是某个C++对象,除非那个对象拥有重载了的字符指针转换符。
这样获取他的字符指针
int main(int argc, char* argv[])
{
std::string s="Hello World!"; printf(s.c_str());
return 0;
}
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
string s="Hello World!"; printf(s.c_str());
return 0;
}
在VC++中试过的可以用了