Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Ncurses输出函数仅接受常量数据_C++_File_C++11_Stream_Ncurses - Fatal编程技术网

C++ Ncurses输出函数仅接受常量数据

C++ Ncurses输出函数仅接受常量数据,c++,file,c++11,stream,ncurses,C++,File,C++11,Stream,Ncurses,当getline()从打开的文本文件中获取行时,我正在尝试向窗口添加字符串。使用NCURSE和C++,我做以下工作: string line; //String to hold content of file and be printed ifstream file; //Input file stream file.open(fileName) //Opens file fileName (p

getline()
从打开的文本文件中获取行时,我正在尝试向窗口添加字符串。使用NCURSE和C++,我做以下工作:

string line;                     //String to hold content of file and be printed
ifstream file;                   //Input file stream
file.open(fileName)              //Opens file fileName (provided by function param)

if(file.is_open()) {             //Enters if able to open file                                                                                                                                                                                                   
  while(getline(file, line)) {   //Runs until all lines in file are extracted via ifstream                                                                                                                                                                                                 
  addstr(line);                  //LINE THAT ISN'T WORKING                                                                                                                                                                                                 
  refresh();                                                                                                                                                                                                                      
  }                                                                                                                                                                                                                                 
  file.close();                    //Done with the file                                                                                                                                                                                                 
} 
所以我的问题是。。。如果我想输出非常量数据类型的内容,在ncurses中应该怎么做?我看到的所有输出函数都不接受任何内容。
应该注意的是,如果我只是将文件的内容输出到控制台,那么这个程序工作得非常好,这样就消除了文件读取/打开错误或流中的某些内容的可能性。我在编译时遇到的确切错误是:

错误:无法将参数“2”的“std::\uuuCXX11::string{aka std::\uuuCXX11::basic\u string}”转换为“const char*”,将其转换为“int-waddnstr(WINDOW*,const char*,int)” addstr(行)

如果你需要更多信息,请告诉我


编辑:添加了相关文档的链接。

问题与任何内容的
常量或非
常量没有直接关系

问题在于ncurses'
addstr()
是一个C库函数,它需要以null结尾的C样式字符串

addstr(line.c_str());

您试图作为参数传递一个C++,代码> STD::String 对象,到<代码> AddStr< /COD>()。考虑到

addstr
()本身是一个C库函数,这不会很好地结束

解决方案是使用
std::string
c_str
()方法来获取c样式的字符串

addstr(line.c_str());

这个问题与任何事物的
const
ness或非
const
ness没有直接关系

问题在于ncurses'
addstr()
是一个C库函数,它需要以null结尾的C样式字符串

addstr(line.c_str());

您试图作为参数传递一个C++,代码> STD::String 对象,到<代码> AddStr< /COD>()。考虑到

addstr
()本身是一个C库函数,这不会很好地结束

解决方案是使用
std::string
c_str
()方法来获取c样式的字符串

addstr(line.c_str());

我想我们越来越近了。这解决了编译错误,但现在它不输出文本。我能为你提供更多信息吗?不,这回答了你的问题。如果你想问别的问题,那将是一个新问题。在你的问题中一定要提供一个答案。这个问题中显示的代码无法满足a的要求。我认为我们正在接近。这解决了编译错误,但现在它不输出文本。我能为你提供更多信息吗?不,这回答了你的问题。如果你想问别的问题,那将是一个新问题。在你的问题中一定要提供一个答案。此问题中显示的代码不符合规范的要求。