BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #9110同步于 2008/7/3
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

VC 6中的一个小问题

majun
2008/7/3镜像同步11 回复
VC 6中,自己编了头文件是不是就不能用string类型了?如果可以用,有没有什么需要添加的,比如类型转换函数,系统头文件这类的?
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
rebirthatsix机器人#1 · 2008/7/3
没明白在问什么。。
majun机器人#2 · 2008/7/3
就是在VC中,一个工作区,自己写了一个头文件,一个主程序,主程序要用到自己写的头文件,然后,这样的话,主程序中,或是自己写的头文件中还能不能用string类了? 【 在 rebirthatsix 的大作中提到: 】 : 没明白在问什么。。
tsjwjc机器人#3 · 2008/7/3
为啥不能? 【 在 majun 的大作中提到: 】 : 就是在VC中,一个工作区,自己写了一个头文件,一个主程序,主程序要用到自己写的头文件,然后,这样的话,主程序中,或是自己写的头文件中还能不能用string类了?
rebirthatsix机器人#4 · 2008/7/3
【 在 tsjwjc 的大作中提到: 】 : 为啥不能? 这就是我没看懂的地方 感觉用不用string类和楼主说的情况好像没啥关系。。
majun机器人#5 · 2008/7/3
大家帮忙看一下,以下程序为什么有错,VC6下: 头文件m.h: #ifndef M_H #define M_H void make_plural(const size_t ctr,const string & word,const string & ending ="s"); #endif 程序 m.cpp: #include<iostream> #include<string> using namespace std; #include"m.h" void make_plural(const size_t ctr,const string & word,const string & ending) {cout<<((ctr==1)?word:word+ending);} 主程序: main.cpp: #include<iostream> #include<string> #include"m.h" using namespace std; int main() {string s; cout<<"please input a word"<<endl; cin>>s; make_plural(1,s); make_plural(2,s); return 0; } 程序其实很简单,就是从控制窗口输入一个字符串,然后分别输出它的单数及复数形式,头文件只是对一个函数的声明 这是C++primier书后的一道习题
rebirthatsix机器人#6 · 2008/7/3
报什么错
rebirthatsix机器人#7 · 2008/7/3
try了一下,按照你这样写,肯定是有错的 m.h里没有include <string>,那么你声明的函数原型肯定就是失败的
Ant机器人#8 · 2008/7/4
【 在 majun (我走我路) 的大作中提到: 】 : 大家帮忙看一下,以下程序为什么有错,VC6下: : 头文件m.h: : #ifndef M_H : #define M_H : void make_plural(const size_t ctr,const string & word,const string & ending =" ~~~ : s"); : #endif : 程序 : m.cpp: : #include<iostream> : #include<string> : using namespace std; : #include"m.h" : void make_plural(const size_t ctr,const string & word,const string & ending) : {cout<<((ctr==1)?word:word+ending);} : 主程序: : main.cpp: : #include<iostream> : #include<string> : #include"m.h" : using namespace std; : int main() : {string s; : cout<<"please input a word"<<endl; : cin>>s; : make_plural(1,s); : make_plural(2,s); : return 0; : } : 程序其实很简单,就是从控制窗口输入一个字符串,然后分别输出它的单数及复数形式,头文件只是对一个函数的声明 : 这是C++primier书后的一道习题
majun机器人#9 · 2008/7/6
在头文件中增加了#include<string>后,为什么还是报错? d:\visual c++\vc\msdev98\myprojects\c++ primier 程序\7_26\m.h(4) : error C2143: syntax error : missing ',' before '&' d:\visual c++\vc\msdev98\myprojects\c++ primier 程序\7_26\m.h(4) : error C2059: syntax error : '&' d:\visual c++\vc\msdev98\myprojects\c++ primier 程序\7_26\main.cpp(9) : error C2664: 'make_plural' : cannot convert parameter 2 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const int' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called d:\visual c++\vc\msdev98\myprojects\c++ primier 程序\7_26\main.cpp(10) : error C2664: 'make_plural' : cannot convert parameter 2 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const int' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Error executing cl.exe. 【 在 rebirthatsix 的大作中提到: 】 : try了一下,按照你这样写,肯定是有错的 : m.h里没有include <string>,那么你声明的函数原型肯定就是失败的