简体   繁体   English

类接收一个 char const * 作为参数(如何在代码中声明 txt.)

[英]class receives an char const * as parameter (how to declare txt. in code)

my Problem is that I try to write a code to do an algorithm in a graph.我的问题是我尝试编写代码来在图中执行算法。 Our prof gave us a header with classes and functions, that can construct a graph.我们的教授给了我们一个包含类和函数的标题,可以构建一个图形。

Graph::Graph(char const * filename, DirType dtype)

You see that the second argument is if the graph is directed or not, but my Problem is that I have to take a txt.你看到第二个参数是图形是否有向,但我的问题是我必须拿一个txt。 data (in which the graph is described (#of nodes, all edges etc.)) and give it as an argument to the class.数据(其中描述了图(节点数、所有边等))并将其作为参数提供给类。

A year ago I did a similar task but I can't remember how I gave my txt data as an argument into the class but it was something like:一年前我做了一个类似的任务,但我不记得我是如何将我的 txt 数据作为参数提供给类的,但它是这样的:

graph.txt

main(){
   ... = graph.txt
   Graph g(..., Graph::directed);

thanks in advance to everyone that wants to help me!在此先感谢所有想帮助我的人!

The argument is called filename , which suggests you're just supposed to pass… a filename.该参数称为filename ,这表明您应该传递……一个文件名。

Graph g("graph.txt", Graph::directed);

That's it.就是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM