Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.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++ 字符串流错误,不是c_str_C++_Linux - Fatal编程技术网

C++ 字符串流错误,不是c_str

C++ 字符串流错误,不是c_str,c++,linux,C++,Linux,我有一段代码在VisualStudio中工作,但不会在我的大学集群上编译。集群使用icc编译器,我的makefile如下: CC=icc DEPENDENCY = Polymer.h %.o:%.c $(DEPENDENCY) $(CC) -03 -xSSE4.2 -axAVX, CORE-AVX-I, CORE-AVX2 PolymerExe: Main.o Polymer.o CC -o PoymerExe Main.o Polymer.o -I 所有的错

我有一段代码在VisualStudio中工作,但不会在我的大学集群上编译。集群使用icc编译器,我的makefile如下:

CC=icc
DEPENDENCY = Polymer.h

%.o:%.c $(DEPENDENCY)
        $(CC) -03 -xSSE4.2 -axAVX, CORE-AVX-I, CORE-AVX2
PolymerExe: Main.o Polymer.o
        CC -o PoymerExe Main.o Polymer.o -I
所有的错误似乎都与字符串有关,因此我将只粘贴那些相关的位(否则这是大量代码)

在梅因之前

#include"Polymer.h"
#include<iostream>
#include<fstream>
#include<ctime>
#include<iomanip>
#include <sstream>
#include <stdlib.h>

using namespace std;
我也用我的名字试过了,也有同样的错误。 谢谢你抽出时间,
Jenny

您可能有两个问题:第一个也是确定的问题是将指向成员函数的指针传递给
std::ofstream
构造函数。你不叫它。做某事

ofstream aFile(myName.str());
//                       ^^
// Note parentheses to call the member function
相反

另一个可能的问题是,C++11标准提供了使用
std::string
作为文件流
open
调用(以及在文件流构造函数中)的参数的可能性。在此之前,您只能使用
const char*


<> P>所以如果英特尔C++编译器支持C++ 11(或更高版本),那么编译时可能需要添加一个标志来启用C++ 11(或更高版本)。或者在打开文件流时必须传递一个
const char*

而不是
流文件(myName.str)
使用
流文件(myName.str().c_str())
流文件(myName.str)
str
是一个函数:所以您应该调用它:
流文件(myName.str())
“*我将只粘贴那些相关的位(否则这将是大量的代码)*”正确的做法是制作一个显示您的问题的小程序,并将其张贴在此处。您可以阅读如何创建;这样做可能会为你的问题找到更好的答案。@TobySpeight更有趣的是,撰写MCVE的过程往往会让答案变得显而易见,而问题变得不必要。
Main.cpp:27:30: error: no matching function for call to ‘std::basic_ofstream<char>::basic_ofstream(std::basic_stringstream<char>::__string_type)’
   ofstream aFile(myName.str());
                              ^
Main.cpp:27:30: note: candidates are:
In file included from Main.cpp:4:0:
/usr/include/c++/4.8.2/fstream:640:7: note: std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
       basic_ofstream(const char* __s,
       ^
/usr/include/c++/4.8.2/fstream:640:7: note:   no known conversion for argument 1 from ‘std::basic_stringstream<char>::__string_type {aka std::basic_string<char>}’ to ‘const char*’
/usr/include/c++/4.8.2/fstream:625:7: note: std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char; _Traits = std::char_traits<char>]
       basic_ofstream(): __ostream_type(), _M_filebuf()
       ^
/usr/include/c++/4.8.2/fstream:625:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/4.8.2/fstream:599:11: note: std::basic_ofstream<char>::basic_ofstream(const std::basic_ofstream<char>&)
     class basic_ofstream : public basic_ostream<_CharT,_Traits>
           ^
/usr/include/c++/4.8.2/fstream:599:11: note:   no known conversion for argument 1 from ‘std::basic_stringstream<char>::__string_type {aka std::basic_string<char>}’ to ‘const std::basic_ofstream<char>&’
make: *** [Main.o] Error 1
Main.cpp: In function ‘int main()’:
Main.cpp:27:25: error: ‘std::stringstream’ has no member named ‘c_str’
   ofstream aFile(myName.c_str);
                         ^
make: *** [Main.o] Error 1
ofstream aFile(myName.str());
//                       ^^
// Note parentheses to call the member function