我在 while 循环中使用 std::getline 并使用 cout 打印输出,我发现打印时我的行的开头被切断:
按预期工作:
std::string line;
while(std::getline(csv, line)) {
std::cout << line << std::endl
}
Run Code Online (Sandbox Code Playgroud)
没有按预期工作,从我的行中删除前两个字符
std::string line;
while(std::getline(csv, line)) {
std::cout << line << " " << std::endl
}
Run Code Online (Sandbox Code Playgroud)
我以前从未注意到这种行为,为什么现在会发生?
编译基本类和标题时出现此错误.不确定我是否遗漏了明显的东西?如果需要,可以提供任何其他细节.
注意:我#include <string>在Event.h中添加了错误,但错误仍然存在.
Event.cpp
#include "Event.h"
#include <string>
std::string Event::getLabel() {
return label;
}
Run Code Online (Sandbox Code Playgroud)
Event.h
#ifndef EVENT_H
#define EVENT_H
#define EVENT_STOP 0
#define EVENT_START 1
class Event {
private:
protected:
double time;
std::string label;
int type; // EVENT_START OR EVENT_STOP
public:
std::string getLabel();
};
#endif
Run Code Online (Sandbox Code Playgroud)
编译和错误
g++ -c -Wall -pedantic correngine.cpp
g++ -c -Wall -pedantic CSVManager.cpp
g++ -c -Wall -pedantic ServerEvent.cpp
g++ -c -o UPSEvent.o UPSEvent.cpp
g++ -c -Wall -pedantic CorrelationEngineManager.cpp
g++ -c -Wall -pedantic Event.cpp
Event.cpp:4: error: …Run Code Online (Sandbox Code Playgroud)