为什么结果老是0

vood 2003-10-18 02:30:02
有一个程序,请大哥门帮忙看看
#include <string>

#include <iostream>

#include <fstream>

#include <vector>

using namespace std;

void main(){
int i;


vector<string> v;

ifstream in("e:\buildtree.cpp");

string word;

while(in>>word)

v.push_back(word);

for(i=0;i<v.size();i++);

cout<<i<<endl;






}


为什么不论我换什么文件,结果都是0?

还有,用dev-c++编程的时候,为什么我看不到结果呢?请详细说名一下,谢谢
...全文
67 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
vood 2003-10-19
  • 打赏
  • 举报
回复
system("PAUSE");
加在什么地方啊?
Wolf0403 2003-10-18
  • 打赏
  • 举报
回复
system("PAUSE");
vood 2003-10-18
  • 打赏
  • 举报
回复
dev-c++,显示结果的时候速度太快
一闪就没有了
怎么办?
oyd 2003-10-18
  • 打赏
  • 举报
回复
vector有那么用的吗?
#pragma warning(disable:4786)
#include <string>
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

void main()
{
vector<string> v;
ifstream in ("D:\\test.cpp");
string word;

while (in >> word)
{
v.push_back (word);
}
for (vector<string>::const_iterator i = v.begin (); i < v.end (); i++)
{
cout << *i << endl;
}
}
Andy84920 2003-10-18
  • 打赏
  • 举报
回复
若在LINUX下面呢?

应该是直接: /home/linuxsir/c++/debug.cpp
而不是: //home/linuxsir/c++/debug.cpp吧?
daizh 2003-10-18
  • 打赏
  • 举报
回复
#include <string>

#include <iostream>

#include <fstream>

#include <vector>

using namespace std;

void main(){
int i;


vector<string> v;

ifstream in("e:\buildtree.cpp");//此处路径用法是错误的应该为ifstream in("e:\\buildtree.cpp");

string word;

while(in>>word)

v.push_back(word);

for(i=0;i<v.size();i++);

cout<<i<<endl;






}
clarkralf 2003-10-18
  • 打赏
  • 举报
回复
我用VS.net 2003编译可以通过

#include <string>

#include <iostream>

#include <fstream>

#include <vector>

using namespace std;

void main(){
int i;


vector<string> v;

ifstream in("debug.cpp");//------------>我调试的文件

string word;

while(in>>word)
{

v.push_back(word);
cout<<word<<" ";//--------------->我加的
}

for(i=0;i<v.size ();i++);

cout<<i<<endl;
}

可以输出该文件的内容。
yaoyang 2003-10-18
  • 打赏
  • 举报
回复
vc 本来就是那样的啊你有调试去实验你的结果就可以看到了啊

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧